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 228870
Collapse All | Expand All

(-)a/beans/nbproject/project.xml (-1 / +1 lines)
Lines 150-156 Link Here
150
                    <build-prerequisite/>
150
                    <build-prerequisite/>
151
                    <compile-dependency/>
151
                    <compile-dependency/>
152
                    <run-dependency>
152
                    <run-dependency>
153
                        <specification-version>0.95</specification-version>
153
                        <specification-version>0.122</specification-version>
154
                    </run-dependency>
154
                    </run-dependency>
155
                </dependency>
155
                </dependency>
156
                <dependency>
156
                <dependency>
(-)a/beans/src/org/netbeans/modules/beans/addproperty/AddPropertyCodeGenerator.java (-6 / +9 lines)
Lines 68-74 Link Here
68
import javax.swing.text.StyledDocument;
68
import javax.swing.text.StyledDocument;
69
import org.netbeans.api.editor.guards.GuardedSection;
69
import org.netbeans.api.editor.guards.GuardedSection;
70
import org.netbeans.api.editor.guards.GuardedSectionManager;
70
import org.netbeans.api.editor.guards.GuardedSectionManager;
71
import org.netbeans.api.java.source.ClasspathInfo;
71
import org.netbeans.api.java.source.CodeStyle;
72
import org.netbeans.api.java.source.CompilationController;
72
import org.netbeans.api.java.source.CompilationController;
73
import org.netbeans.api.java.source.CompilationInfo;
73
import org.netbeans.api.java.source.CompilationInfo;
74
import org.netbeans.api.java.source.JavaSource;
74
import org.netbeans.api.java.source.JavaSource;
Lines 78-84 Link Here
78
import org.netbeans.api.java.source.TreeUtilities;
78
import org.netbeans.api.java.source.TreeUtilities;
79
import org.netbeans.api.java.source.WorkingCopy;
79
import org.netbeans.api.java.source.WorkingCopy;
80
import org.netbeans.editor.GuardedException;
80
import org.netbeans.editor.GuardedException;
81
import org.netbeans.editor.Utilities;
82
import org.netbeans.modules.editor.indent.api.Reformat;
81
import org.netbeans.modules.editor.indent.api.Reformat;
83
import org.netbeans.spi.editor.codegen.CodeGenerator;
82
import org.netbeans.spi.editor.codegen.CodeGenerator;
84
import org.openide.DialogDescriptor;
83
import org.openide.DialogDescriptor;
Lines 126-137 Link Here
126
125
127
    public void perform(FileObject file, JTextComponent pane) {
126
    public void perform(FileObject file, JTextComponent pane) {
128
        JButton ok = new JButton(NbBundle.getMessage(AddPropertyCodeGenerator.class, "LBL_ButtonOK"));
127
        JButton ok = new JButton(NbBundle.getMessage(AddPropertyCodeGenerator.class, "LBL_ButtonOK"));
129
        final AddPropertyPanel addPropertyPanel = new AddPropertyPanel(file, className, existingFields, pcsName, vcsName, ok);
128
        CodeStyle cs = CodeStyle.getDefault(pane.getDocument());
129
        if(cs == null) {
130
            cs = CodeStyle.getDefault(file);
131
        }
132
        final AddPropertyPanel addPropertyPanel = new AddPropertyPanel(file, className, cs, existingFields, pcsName, vcsName, ok);
130
        String caption = NbBundle.getMessage(AddPropertyCodeGenerator.class, "CAP_AddProperty");
133
        String caption = NbBundle.getMessage(AddPropertyCodeGenerator.class, "CAP_AddProperty");
131
        String cancel = NbBundle.getMessage(AddPropertyCodeGenerator.class, "LBL_ButtonCancel");
134
        String cancel = NbBundle.getMessage(AddPropertyCodeGenerator.class, "LBL_ButtonCancel");
132
        DialogDescriptor dd = new DialogDescriptor(addPropertyPanel,caption, true, new Object[] {ok,cancel}, ok, DialogDescriptor.DEFAULT_ALIGN, null, null);
135
        DialogDescriptor dd = new DialogDescriptor(addPropertyPanel,caption, true, new Object[] {ok,cancel}, ok, DialogDescriptor.DEFAULT_ALIGN, null, null);
133
        if (DialogDisplayer.getDefault().notify(dd) == ok) {
136
        if (DialogDisplayer.getDefault().notify(dd) == ok) {
134
            insertCode2(file, pane, addPropertyPanel.getAddPropertyConfig());
137
            insertCode2(file, pane, addPropertyPanel.getAddPropertyConfig(), cs);
135
        }
138
        }
136
    }
139
    }
137
140
Lines 140-149 Link Here
140
     * @see <a href=http://www.netbeans.org/issues/show_bug.cgi?id=162853>162853</a>
143
     * @see <a href=http://www.netbeans.org/issues/show_bug.cgi?id=162853>162853</a>
141
     * @see <a href=http://www.netbeans.org/issues/show_bug.cgi?id=162630>162630</a>
144
     * @see <a href=http://www.netbeans.org/issues/show_bug.cgi?id=162630>162630</a>
142
     */
145
     */
143
    static void insertCode2(final FileObject file, final JTextComponent pane, final AddPropertyConfig config) {
146
    static void insertCode2(final FileObject file, final JTextComponent pane, final AddPropertyConfig config, CodeStyle cs) {
144
            final Document doc = pane.getDocument();
147
            final Document doc = pane.getDocument();
145
            final Reformat r = Reformat.get(pane.getDocument());
148
            final Reformat r = Reformat.get(pane.getDocument());
146
            final String code = new AddPropertyGenerator().generate(config);
149
            final String code = new AddPropertyGenerator().generate(config, cs);
147
            final Position[] bounds = new Position[2];
150
            final Position[] bounds = new Position[2];
148
            
151
            
149
            final int offset[] = new int[1];
152
            final int offset[] = new int[1];
(-)a/beans/src/org/netbeans/modules/beans/addproperty/AddPropertyGenerator.java (-21 / +24 lines)
Lines 50-55 Link Here
50
import javax.script.ScriptEngine;
50
import javax.script.ScriptEngine;
51
import javax.script.ScriptEngineManager;
51
import javax.script.ScriptEngineManager;
52
import javax.script.ScriptException;
52
import javax.script.ScriptException;
53
import org.netbeans.api.java.source.CodeStyle;
54
import org.netbeans.api.java.source.CodeStyleUtils;
53
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileUtil;
56
import org.openide.filesystems.FileUtil;
55
import org.openide.util.Exceptions;
57
import org.openide.util.Exceptions;
Lines 60-74 Link Here
60
 */
62
 */
61
public class AddPropertyGenerator {
63
public class AddPropertyGenerator {
62
64
63
    public String generate(AddPropertyConfig addPropertyConfig) {
65
    public String generate(AddPropertyConfig addPropertyConfig, CodeStyle cs) {
64
        ScriptEngine scriptEngine = getScriptEngine();
66
        ScriptEngine scriptEngine = getScriptEngine();
65
        if (scriptEngine != null) {
67
        if (scriptEngine != null) {
66
            FileObject template = getTemplateFileObject(addPropertyConfig.getTEMPLATE_PATH());
68
            FileObject template = getTemplateFileObject(addPropertyConfig.getTEMPLATE_PATH());
67
            if (template != null && template.isValid()) {
69
            if (template != null && template.isValid()) {
68
                final String type = addPropertyConfig.getType().trim();
70
                final String type = addPropertyConfig.getType().trim();
69
                final String name = addPropertyConfig.getName().trim();
71
                final String name = addPropertyConfig.getName().trim();
72
                final String fieldName = CodeStyleUtils.addPrefixSuffix(name,
73
                        addPropertyConfig.isStatic() ? cs.getStaticFieldNamePrefix() : cs.getFieldNamePrefix(),
74
                        addPropertyConfig.isStatic() ? cs.getStaticFieldNameSuffix() : cs.getFieldNameSuffix());
75
                final String paramName = CodeStyleUtils.addPrefixSuffix(name,
76
                        cs.getParameterNamePrefix(),
77
                        cs.getParameterNameSuffix());
78
                final String paramIndex = CodeStyleUtils.addPrefixSuffix("index", //NOI18N
79
                        cs.getParameterNamePrefix(),
80
                        cs.getParameterNameSuffix());
81
                final String propName = CodeStyleUtils.addPrefixSuffix(
82
                        addPropertyConfig.getPopName().trim(),
83
                        cs.getStaticFieldNamePrefix(),
84
                        cs.getStaticFieldNameSuffix());
70
                final String initializer = addPropertyConfig.getInitializer().trim();
85
                final String initializer = addPropertyConfig.getInitializer().trim();
71
                String access = "";
86
                String access;
72
                switch (addPropertyConfig.getAccess()) {
87
                switch (addPropertyConfig.getAccess()) {
73
                    case PRIVATE:
88
                    case PRIVATE:
74
                        access = "private "; // NOI18N
89
                        access = "private "; // NOI18N
Lines 93-100 Link Here
93
                scriptContext.setAttribute("type", type, ScriptContext.ENGINE_SCOPE); // NOI18N
108
                scriptContext.setAttribute("type", type, ScriptContext.ENGINE_SCOPE); // NOI18N
94
                scriptContext.setAttribute("className", addPropertyConfig.getClassName(), ScriptContext.ENGINE_SCOPE); // NOI18N
109
                scriptContext.setAttribute("className", addPropertyConfig.getClassName(), ScriptContext.ENGINE_SCOPE); // NOI18N
95
                scriptContext.setAttribute("name", name, ScriptContext.ENGINE_SCOPE); // NOI18N
110
                scriptContext.setAttribute("name", name, ScriptContext.ENGINE_SCOPE); // NOI18N
111
                scriptContext.setAttribute("fieldName", fieldName, ScriptContext.ENGINE_SCOPE); // NOI18N
112
                scriptContext.setAttribute("paramName", paramName, ScriptContext.ENGINE_SCOPE); // NOI18N
113
                scriptContext.setAttribute("paramIndex", paramIndex, ScriptContext.ENGINE_SCOPE); // NOI18N
96
                scriptContext.setAttribute("initializer", initializer, ScriptContext.ENGINE_SCOPE); // NOI18N
114
                scriptContext.setAttribute("initializer", initializer, ScriptContext.ENGINE_SCOPE); // NOI18N
97
                scriptContext.setAttribute("capitalizedName", capitalize(name).toString(), ScriptContext.ENGINE_SCOPE); // NOI18N
115
                scriptContext.setAttribute("capitalizedName", CodeStyleUtils.getCapitalizedName(name), ScriptContext.ENGINE_SCOPE); // NOI18N
116
                scriptContext.setAttribute("getterName", CodeStyleUtils.computeGetterName(fieldName, type.equalsIgnoreCase("boolean"), addPropertyConfig.isStatic(), cs), ScriptContext.ENGINE_SCOPE); // NOI18N
117
                scriptContext.setAttribute("setterName", CodeStyleUtils.computeSetterName(fieldName, addPropertyConfig.isStatic(), cs), ScriptContext.ENGINE_SCOPE); // NOI18N
98
                scriptContext.setAttribute("static", Boolean.valueOf(addPropertyConfig.isStatic()), ScriptContext.ENGINE_SCOPE); // NOI18N
118
                scriptContext.setAttribute("static", Boolean.valueOf(addPropertyConfig.isStatic()), ScriptContext.ENGINE_SCOPE); // NOI18N
99
                scriptContext.setAttribute("final", Boolean.valueOf(addPropertyConfig.isFinale()), ScriptContext.ENGINE_SCOPE); // NOI18N
119
                scriptContext.setAttribute("final", Boolean.valueOf(addPropertyConfig.isFinale()), ScriptContext.ENGINE_SCOPE); // NOI18N
100
                AddPropertyConfig.GENERATE generateGetterSetter = addPropertyConfig.getGenerateGetterSetter();
120
                AddPropertyConfig.GENERATE generateGetterSetter = addPropertyConfig.getGenerateGetterSetter();
Lines 106-112 Link Here
106
                        ScriptContext.ENGINE_SCOPE);
126
                        ScriptContext.ENGINE_SCOPE);
107
                scriptContext.setAttribute("generateJavadoc", Boolean.valueOf(addPropertyConfig.isGenerateJavadoc()), ScriptContext.ENGINE_SCOPE); // NOI18N
127
                scriptContext.setAttribute("generateJavadoc", Boolean.valueOf(addPropertyConfig.isGenerateJavadoc()), ScriptContext.ENGINE_SCOPE); // NOI18N
108
                scriptContext.setAttribute("bound", Boolean.valueOf(addPropertyConfig.isBound()), ScriptContext.ENGINE_SCOPE); // NOI18N
128
                scriptContext.setAttribute("bound", Boolean.valueOf(addPropertyConfig.isBound()), ScriptContext.ENGINE_SCOPE); // NOI18N
109
                scriptContext.setAttribute("PROP_NAME", addPropertyConfig.getPopName().trim(), ScriptContext.ENGINE_SCOPE); // NOI18N
129
                scriptContext.setAttribute("PROP_NAME", propName, ScriptContext.ENGINE_SCOPE); // NOI18N
110
                scriptContext.setAttribute("vetoable", Boolean.valueOf(addPropertyConfig.isVetoable()), ScriptContext.ENGINE_SCOPE); // NOI18N
130
                scriptContext.setAttribute("vetoable", Boolean.valueOf(addPropertyConfig.isVetoable()), ScriptContext.ENGINE_SCOPE); // NOI18N
111
                scriptContext.setAttribute("indexed", Boolean.valueOf(addPropertyConfig.isIndexed()), ScriptContext.ENGINE_SCOPE); // NOI18N
131
                scriptContext.setAttribute("indexed", Boolean.valueOf(addPropertyConfig.isIndexed()), ScriptContext.ENGINE_SCOPE); // NOI18N
112
                scriptContext.setAttribute("propertyChangeSupport", addPropertyConfig.getPropertyChangeSupportName(), ScriptContext.ENGINE_SCOPE); // NOI18N
132
                scriptContext.setAttribute("propertyChangeSupport", addPropertyConfig.getPropertyChangeSupportName(), ScriptContext.ENGINE_SCOPE); // NOI18N
Lines 153-173 Link Here
153
    private static ScriptEngine getScriptEngine() {
173
    private static ScriptEngine getScriptEngine() {
154
        return new ScriptEngineManager().getEngineByName("freemarker"); // NOI18N
174
        return new ScriptEngineManager().getEngineByName("freemarker"); // NOI18N
155
    }
175
    }
156
157
    private static StringBuilder capitalize(String string) {
158
        StringBuilder sb = new StringBuilder(string);
159
        while (sb.length() > 1 && sb.charAt(0) == '_') { //NOI18N
160
            sb.deleteCharAt(0);
161
        }
162
163
        //Beans naming convention, #165241
164
        if (sb.length() > 1 && Character.isUpperCase(sb.charAt(1))) {
165
            return sb;
166
        }
167
168
        if (sb.length() > 0) {
169
            sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
170
        }
171
        return sb;
172
    }
173
}
176
}
(-)a/beans/src/org/netbeans/modules/beans/addproperty/AddPropertyPanel.form (-1 / +1 lines)
Lines 1-4 Link Here
1
<?xml version="1.1" encoding="UTF-8" ?>
1
<?xml version="1.0" encoding="UTF-8" ?>
2
2
3
<Form version="1.5" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.5" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <NonVisualComponents>
4
  <NonVisualComponents>
(-)a/beans/src/org/netbeans/modules/beans/addproperty/AddPropertyPanel.java (-2 / +5 lines)
Lines 52-57 Link Here
52
import javax.swing.event.DocumentEvent;
52
import javax.swing.event.DocumentEvent;
53
import javax.swing.event.DocumentListener;
53
import javax.swing.event.DocumentListener;
54
import org.netbeans.api.java.source.ClasspathInfo;
54
import org.netbeans.api.java.source.ClasspathInfo;
55
import org.netbeans.api.java.source.CodeStyle;
55
import org.netbeans.api.java.source.ElementHandle;
56
import org.netbeans.api.java.source.ElementHandle;
56
import org.netbeans.api.java.source.ui.TypeElementFinder;
57
import org.netbeans.api.java.source.ui.TypeElementFinder;
57
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileObject;
Lines 71-84 Link Here
71
    private DocumentListener propNameTextFieldDocumentListener;
72
    private DocumentListener propNameTextFieldDocumentListener;
72
    private FileObject file;
73
    private FileObject file;
73
    private String className;
74
    private String className;
75
    private final CodeStyle cs;
74
    private List<String> existingFields;
76
    private List<String> existingFields;
75
    private String[] pcsName;
77
    private String[] pcsName;
76
    private String[] vcsName;
78
    private String[] vcsName;
77
    private JButton okButton;
79
    private JButton okButton;
78
    
80
    
79
    public AddPropertyPanel(FileObject file, String className, List<String> existingFields, String[] pcsName, String[] vcsName, JButton okButton) {
81
    public AddPropertyPanel(FileObject file, String className, CodeStyle cs, List<String> existingFields, String[] pcsName, String[] vcsName, JButton okButton) {
80
        this.file = file;
82
        this.file = file;
81
        this.className = className;
83
        this.className = className;
84
        this.cs = cs;
82
        this.existingFields = existingFields;
85
        this.existingFields = existingFields;
83
        this.pcsName = pcsName;
86
        this.pcsName = pcsName;
84
        this.vcsName = vcsName;
87
        this.vcsName = vcsName;
Lines 162-168 Link Here
162
            }
165
            }
163
        }
166
        }
164
        
167
        
165
        final String previewTemplate = new AddPropertyGenerator().generate(getAddPropertyConfig());
168
        final String previewTemplate = new AddPropertyGenerator().generate(getAddPropertyConfig(), cs);
166
        previewEditorPane.setText(previewTemplate);
169
        previewEditorPane.setText(previewTemplate);
167
        
170
        
168
        String error = resolveError();
171
        String error = resolveError();
(-)a/beans/src/org/netbeans/modules/beans/resources/templates/AddProperty.freemarker (-19 / +19 lines)
Lines 5-11 Link Here
5
    <#assign vetoableChangeSupport="vetoableChangeSupport">
5
    <#assign vetoableChangeSupport="vetoableChangeSupport">
6
</#if>
6
</#if>
7
7
8
    ${access}<#if static >static </#if><#if final >final </#if>${type}<#if indexed >[]</#if> ${name}<#if final > = ${initializer}<#else><#if initializer != "" > = ${initializer}</#if></#if>;
8
    ${access}<#if static >static </#if><#if final >final </#if>${type}<#if indexed >[]</#if> ${fieldName}<#if final > = ${initializer}<#else><#if initializer != "" > = ${initializer}</#if></#if>;
9
<#if bound >
9
<#if bound >
10
10
11
    public static final String ${PROP_NAME} = "${name}";
11
    public static final String ${PROP_NAME} = "${name}";
Lines 19-26 Link Here
19
     * @return the value of ${name}
19
     * @return the value of ${name}
20
     */
20
     */
21
</#if>
21
</#if>
22
    public <#if static >static </#if>${type}<#if indexed >[]</#if> <#if type = "boolean" >is<#else>get</#if>${capitalizedName}() {
22
    public <#if static >static </#if>${type}<#if indexed >[]</#if> ${getterName}() {
23
        return ${name};
23
        return ${fieldName};
24
    }
24
    }
25
</#if>
25
</#if>
26
<#if generateSetter >
26
<#if generateSetter >
Lines 30-51 Link Here
30
    /**
30
    /**
31
     * Set the value of ${name}
31
     * Set the value of ${name}
32
     *
32
     *
33
     * @param ${name} new value of ${name}
33
     * @param ${paramName} new value of ${name}
34
<#if vetoable>
34
<#if vetoable>
35
     * @throws java.beans.PropertyVetoException
35
     * @throws java.beans.PropertyVetoException
36
</#if>
36
</#if>
37
     */
37
     */
38
</#if>
38
</#if>
39
    public <#if static >static </#if>void set${capitalizedName}(${type}<#if indexed >[]</#if> ${name})<#if vetoable> throws java.beans.PropertyVetoException</#if> {
39
    public <#if static >static </#if>void ${setterName}(${type}<#if indexed >[]</#if> ${paramName})<#if vetoable> throws java.beans.PropertyVetoException</#if> {
40
<#if bound >
40
<#if bound >
41
        ${type}<#if indexed >[]</#if> old${capitalizedName} = this.${name};
41
        ${type}<#if indexed >[]</#if> old${capitalizedName} = this.${fieldName};
42
<#if vetoable> 
42
<#if vetoable> 
43
        ${vetoableChangeSupport}.fireVetoableChange(${PROP_NAME}, old${capitalizedName}, ${name});
43
        ${vetoableChangeSupport}.fireVetoableChange(${PROP_NAME}, old${capitalizedName}, ${paramName});
44
</#if>
44
</#if>
45
</#if>
45
</#if>
46
        <#if static >${className}.<#else>this.</#if>${name} = ${name};
46
        <#if static >${className}.<#else>this.</#if>${fieldName} = ${paramName};
47
<#if bound >
47
<#if bound >
48
        ${propertyChangeSupport}.firePropertyChange(${PROP_NAME}, old${capitalizedName}, ${name});
48
        ${propertyChangeSupport}.firePropertyChange(${PROP_NAME}, old${capitalizedName}, ${paramName});
49
</#if>
49
</#if>
50
    }
50
    }
51
</#if>
51
</#if>
Lines 57-68 Link Here
57
    /**
57
    /**
58
     * Get the value of ${name} at specified index
58
     * Get the value of ${name} at specified index
59
     *
59
     *
60
     * @param index
60
     * @param ${paramIndex} the index of ${name}
61
     * @return the value of ${name} at specified index
61
     * @return the value of ${name} at specified index
62
     */
62
     */
63
</#if>
63
</#if>
64
    public <#if static >static </#if>${type} <#if type = "boolean" >is<#else>get</#if>${capitalizedName}(int index) {
64
    public <#if static >static </#if>${type} ${getterName}(int ${paramIndex}) {
65
        return <#if !static >this.</#if>${name}[index];
65
        return <#if !static >this.</#if>${fieldName}[${paramIndex}];
66
    }
66
    }
67
</#if>
67
</#if>
68
<#if generateSetter >
68
<#if generateSetter >
Lines 70-92 Link Here
70
    /**
70
    /**
71
     * Set the value of ${name} at specified index.
71
     * Set the value of ${name} at specified index.
72
     *
72
     *
73
     * @param index
73
     * @param ${paramIndex} the index of ${name}
74
     * @param new${capitalizedName} new value of ${name} at specified index
74
     * @param ${paramName} new value of ${name} at specified index
75
<#if vetoable>
75
<#if vetoable>
76
     * @throws java.beans.PropertyVetoException
76
     * @throws java.beans.PropertyVetoException
77
</#if>
77
</#if>
78
     */
78
     */
79
</#if>
79
</#if>
80
    public <#if static >static </#if>void set${capitalizedName}(int index, ${type} new${capitalizedName})<#if vetoable> throws java.beans.PropertyVetoException</#if> {
80
    public <#if static >static </#if>void ${setterName}(int ${paramIndex}, ${type} ${paramName})<#if vetoable> throws java.beans.PropertyVetoException</#if> {
81
<#if bound >
81
<#if bound >
82
        ${type} old${capitalizedName} = this.${name}[index];
82
        ${type} old${capitalizedName} = this.${fieldName}[${paramIndex}];
83
<#if vetoable> 
83
<#if vetoable> 
84
        ${vetoableChangeSupport}.fireVetoableChange(${PROP_NAME}, old${capitalizedName}, new${capitalizedName});
84
        ${vetoableChangeSupport}.fireVetoableChange(${PROP_NAME}, old${capitalizedName}, ${paramName});
85
</#if>
85
</#if>
86
</#if>
86
</#if>
87
        <#if !static >this.</#if>${name}[index] = new${capitalizedName};
87
        <#if !static >this.</#if>${fieldName}[${paramIndex}] = ${paramName};
88
<#if bound >
88
<#if bound >
89
        ${propertyChangeSupport}.fireIndexedPropertyChange(${PROP_NAME}, index, old${capitalizedName}, new${capitalizedName});
89
        ${propertyChangeSupport}.fireIndexedPropertyChange(${PROP_NAME}, ${paramIndex}, old${capitalizedName}, ${paramName});
90
</#if>
90
</#if>
91
    }
91
    }
92
</#if>
92
</#if>
(-)a/java.editor/nbproject/project.xml (-1 / +1 lines)
Lines 231-237 Link Here
231
                    <build-prerequisite/>
231
                    <build-prerequisite/>
232
                    <compile-dependency/>
232
                    <compile-dependency/>
233
                    <run-dependency>
233
                    <run-dependency>
234
                        <specification-version>0.121</specification-version>
234
                        <specification-version>0.122</specification-version>
235
                    </run-dependency>
235
                    </run-dependency>
236
                </dependency>
236
                </dependency>
237
                <dependency>
237
                <dependency>
(-)a/java.editor/src/org/netbeans/modules/editor/java/JavaCodeTemplateProcessor.java (-1 / +1 lines)
Lines 868-874 Link Here
868
                            };
868
                            };
869
                        }
869
                        }
870
                    };
870
                    };
871
                    Iterator<String> names = Utilities.varNamesSuggestions(type, suggestedName, null, cInfo.getTypes(), cInfo.getElements(), loc, isConst).iterator();
871
                    Iterator<String> names = Utilities.varNamesSuggestions(type, suggestedName, null, cInfo.getTypes(), cInfo.getElements(), loc, isConst, null, null, null).iterator();
872
                    if (names.hasNext())
872
                    if (names.hasNext())
873
                        return names.next();
873
                        return names.next();
874
                }
874
                }
(-)a/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java (-11 / +23 lines)
Lines 53-58 Link Here
53
import java.awt.Graphics;
53
import java.awt.Graphics;
54
import java.awt.event.InputEvent;
54
import java.awt.event.InputEvent;
55
import java.awt.event.KeyEvent;
55
import java.awt.event.KeyEvent;
56
import java.io.IOException;
56
import java.net.URL;
57
import java.net.URL;
57
import java.util.*;
58
import java.util.*;
58
import java.util.concurrent.atomic.AtomicBoolean;
59
import java.util.concurrent.atomic.AtomicBoolean;
Lines 211-221 Link Here
211
        }
212
        }
212
    }
213
    }
213
214
214
    public static JavaCompletionItem createGetterSetterMethodItem(CompilationInfo info, VariableElement elem, TypeMirror type, int substitutionOffset, boolean setter) {
215
    public static JavaCompletionItem createGetterSetterMethodItem(CompilationInfo info, VariableElement elem, TypeMirror type, int substitutionOffset, String name, boolean setter) {
215
        switch (elem.getKind()) {
216
        switch (elem.getKind()) {
216
            case ENUM_CONSTANT:
217
            case ENUM_CONSTANT:
217
            case FIELD:
218
            case FIELD:
218
                return new GetterSetterMethodItem(info, elem, type, substitutionOffset, setter);
219
                return new GetterSetterMethodItem(info, elem, type, substitutionOffset, name, setter);
219
            default:
220
            default:
220
                throw new IllegalArgumentException("kind=" + elem.getKind());
221
                throw new IllegalArgumentException("kind=" + elem.getKind());
221
        }
222
        }
Lines 1881-1903 Link Here
1881
1882
1882
        protected ElementHandle<VariableElement> elementHandle;
1883
        protected ElementHandle<VariableElement> elementHandle;
1883
        private boolean setter;
1884
        private boolean setter;
1884
        private String simpleName;
1885
        private String paramName;
1885
        private String name;
1886
        private String name;
1886
        private String typeName;
1887
        private String typeName;
1887
        private String sortText;
1888
        private String sortText;
1888
        private String leftText;
1889
        private String leftText;
1889
        private String rightText;
1890
        private String rightText;
1890
1891
1891
        private GetterSetterMethodItem(CompilationInfo info, VariableElement elem, TypeMirror type, int substitutionOffset, boolean setter) {
1892
        private GetterSetterMethodItem(CompilationInfo info, VariableElement elem, TypeMirror type, int substitutionOffset, String name, boolean setter) {
1892
            super(substitutionOffset);
1893
            super(substitutionOffset);
1893
            this.elementHandle = ElementHandle.create(elem);
1894
            this.elementHandle = ElementHandle.create(elem);
1894
            this.setter = setter;
1895
            this.setter = setter;
1895
            this.simpleName = elem.getSimpleName().toString();
1896
            CodeStyle cs = null;
1896
            if (setter) {
1897
            try {
1897
                this.name = "set" + GeneratorUtils.getCapitalizedName(simpleName); //NOI18N
1898
                cs = CodeStyle.getDefault(info.getDocument());
1898
            } else {
1899
            } catch (IOException ex) {
1899
                this.name = (elem.asType().getKind() == TypeKind.BOOLEAN ? "is" : "get") + GeneratorUtils.getCapitalizedName(simpleName); //NOI18N
1900
            }
1900
            }
1901
            if (cs == null) {
1902
                cs = CodeStyle.getDefault(info.getFileObject());
1903
            }
1904
            boolean isStatic = elem.getModifiers().contains(Modifier.STATIC);
1905
            String simpleName = CodeStyleUtils.removePrefixSuffix(elem.getSimpleName(),
1906
                isStatic ? cs.getStaticFieldNamePrefix() : cs.getFieldNamePrefix(),
1907
                isStatic ? cs.getStaticFieldNameSuffix() : cs.getFieldNameSuffix());
1908
            this.paramName = CodeStyleUtils.addPrefixSuffix(
1909
                    simpleName,
1910
                    cs.getParameterNamePrefix(),
1911
                    cs.getParameterNameSuffix());
1912
            this.name = name;
1901
            this.typeName = Utilities.getTypeName(info, type, false).toString();
1913
            this.typeName = Utilities.getTypeName(info, type, false).toString();
1902
        }
1914
        }
1903
1915
Lines 1939-1945 Link Here
1939
                    lText.append(escape(typeName));
1951
                    lText.append(escape(typeName));
1940
                    lText.append(' ');
1952
                    lText.append(' ');
1941
                    lText.append(PARAMETER_NAME_COLOR);
1953
                    lText.append(PARAMETER_NAME_COLOR);
1942
                    lText.append(simpleName);
1954
                    lText.append(paramName);
1943
                    lText.append(COLOR_END);
1955
                    lText.append(COLOR_END);
1944
                }
1956
                }
1945
                lText.append(") - "); //NOI18N
1957
                lText.append(") - "); //NOI18N
Lines 2030-2036 Link Here
2030
            if (setter) {
2042
            if (setter) {
2031
                sb.append(typeName);
2043
                sb.append(typeName);
2032
                sb.append(' ');
2044
                sb.append(' ');
2033
                sb.append(simpleName);
2045
                sb.append(paramName);
2034
            }
2046
            }
2035
            sb.append(") - "); //NOI18N
2047
            sb.append(") - "); //NOI18N
2036
            sb.append(GENERATE_TEXT);
2048
            sb.append(GENERATE_TEXT);
(-)a/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java (-11 / +38 lines)
Lines 245-250 Link Here
245
        
245
        
246
        private ElementHandle element;
246
        private ElementHandle element;
247
        private boolean hasTask;
247
        private boolean hasTask;
248
        private CodeStyle codeStyle;
248
        
249
        
249
        private JavaCompletionQuery(int queryType, int caretOffset, boolean hasTask) {
250
        private JavaCompletionQuery(int queryType, int caretOffset, boolean hasTask) {
250
            this.queryType = queryType;
251
            this.queryType = queryType;
Lines 268-273 Link Here
268
        @Override
269
        @Override
269
        protected void prepareQuery(JTextComponent component) {
270
        protected void prepareQuery(JTextComponent component) {
270
            this.component = component;
271
            this.component = component;
272
            this.codeStyle = CodeStyle.getDefault(component.getDocument());
271
            if (queryType == TOOLTIP_QUERY_TYPE) {
273
            if (queryType == TOOLTIP_QUERY_TYPE) {
272
                this.toolTip = new MethodParamsTipPaintComponent(component);
274
                this.toolTip = new MethodParamsTipPaintComponent(component);
273
            }
275
            }
Lines 2615-2620 Link Here
2615
            }
2617
            }
2616
            controller.toPhase(Phase.ELEMENTS_RESOLVED);
2618
            controller.toPhase(Phase.ELEMENTS_RESOLVED);
2617
            boolean isConst = parent.getKind() == Tree.Kind.VARIABLE && ((VariableTree)parent).getModifiers().getFlags().containsAll(EnumSet.of(FINAL, STATIC));
2619
            boolean isConst = parent.getKind() == Tree.Kind.VARIABLE && ((VariableTree)parent).getModifiers().getFlags().containsAll(EnumSet.of(FINAL, STATIC));
2620
            boolean preferLong = false;
2621
            String csPrefix = null;
2622
            String csSuffix = null;
2623
            if(codeStyle != null) {
2624
                preferLong = codeStyle.preferLongerNames();
2625
                if(env.getScope().getEnclosingMethod() == null) {
2626
                    if(exPath.getParentPath().getParentPath().getLeaf().getKind() == Tree.Kind.METHOD) {
2627
                        csPrefix = codeStyle.getParameterNamePrefix();
2628
                        csSuffix = codeStyle.getParameterNameSuffix();
2629
                    } else if(((VariableTree)parent).getModifiers().getFlags().contains(STATIC)) {
2630
                        csPrefix = codeStyle.getStaticFieldNamePrefix();
2631
                        csSuffix = codeStyle.getStaticFieldNameSuffix();
2632
                    } else {
2633
                        csPrefix = codeStyle.getFieldNamePrefix();
2634
                        csSuffix = codeStyle.getFieldNameSuffix();
2635
                    }
2636
                } else {
2637
                    csPrefix = codeStyle.getLocalVarNamePrefix();
2638
                    csSuffix = codeStyle.getLocalVarNameSuffix();
2639
                }
2640
            }
2618
            if (et.getKind() == Tree.Kind.ANNOTATED_TYPE) {
2641
            if (et.getKind() == Tree.Kind.ANNOTATED_TYPE) {
2619
                et = ((AnnotatedTypeTree)et).getUnderlyingType();
2642
                et = ((AnnotatedTypeTree)et).getUnderlyingType();
2620
                exPath = new TreePath(exPath, et);
2643
                exPath = new TreePath(exPath, et);
Lines 2631-2637 Link Here
2631
                                !illegalForwardRefs.contains(e);
2654
                                !illegalForwardRefs.contains(e);
2632
                    }
2655
                    }
2633
                };
2656
                };
2634
                for (String name : Utilities.varNamesSuggestions(tm, null, prefix, controller.getTypes(), controller.getElements(), controller.getElementUtilities().getLocalMembersAndVars(scope, acceptor), isConst))
2657
                for (String name : Utilities.varNamesSuggestions(tm, null, prefix, controller.getTypes(), controller.getElements(), controller.getElementUtilities().getLocalMembersAndVars(scope, acceptor), isConst, csPrefix, csSuffix, preferLong))
2635
                    results.add(JavaCompletionItem.createVariableItem(env.getController(), name, anchorOffset, true, false));
2658
                    results.add(JavaCompletionItem.createVariableItem(env.getController(), name, anchorOffset, true, false));
2636
                return;
2659
                return;
2637
            }
2660
            }
Lines 2663-2669 Link Here
2663
                                            !illegalForwardRefs.contains(e);
2686
                                            !illegalForwardRefs.contains(e);
2664
                                }
2687
                                }
2665
                            };
2688
                            };
2666
                            for (String name : Utilities.varNamesSuggestions(tm, null, prefix, controller.getTypes(), controller.getElements(), controller.getElementUtilities().getLocalMembersAndVars(scope, acceptor), isConst))
2689
                            for (String name : Utilities.varNamesSuggestions(tm, null, prefix, controller.getTypes(), controller.getElements(),
2690
                                    controller.getElementUtilities().getLocalMembersAndVars(scope, acceptor), isConst,
2691
                                    csPrefix, csSuffix, preferLong))
2667
                                results.add(JavaCompletionItem.createVariableItem(env.getController(), name, anchorOffset, true, false));
2692
                                results.add(JavaCompletionItem.createVariableItem(env.getController(), name, anchorOffset, true, false));
2668
                        }
2693
                        }
2669
                        VariableElement ve = getFieldOrVar(env, e.getSimpleName().toString());
2694
                        VariableElement ve = getFieldOrVar(env, e.getSimpleName().toString());
Lines 2691-2697 Link Here
2691
                                            !illegalForwardRefs.contains(e);
2716
                                            !illegalForwardRefs.contains(e);
2692
                                }
2717
                                }
2693
                            };
2718
                            };
2694
                            for (String name : Utilities.varNamesSuggestions(controller.getTypes().getDeclaredType(te), null, prefix, controller.getTypes(), controller.getElements(), controller.getElementUtilities().getLocalMembersAndVars(scope, acceptor), isConst))
2719
                            for (String name : Utilities.varNamesSuggestions(controller.getTypes().getDeclaredType(te), null, prefix, controller.getTypes(),
2720
                                    controller.getElements(), controller.getElementUtilities().getLocalMembersAndVars(scope, acceptor), isConst,
2721
                                    csPrefix, csSuffix, preferLong))
2695
                                results.add(JavaCompletionItem.createVariableItem(env.getController(), name, anchorOffset, true, false));
2722
                                results.add(JavaCompletionItem.createVariableItem(env.getController(), name, anchorOffset, true, false));
2696
                        }
2723
                        }
2697
                        break;
2724
                        break;
Lines 2795-2801 Link Here
2795
                                    !illegalForwardRefs.contains(e);
2822
                                    !illegalForwardRefs.contains(e);
2796
                        }
2823
                        }
2797
                    };
2824
                    };
2798
                    for (String name : Utilities.varNamesSuggestions(tm, null, prefix, controller.getTypes(), controller.getElements(), controller.getElementUtilities().getLocalMembersAndVars(scope, acceptor), isConst))
2825
                    for (String name : Utilities.varNamesSuggestions(tm, null, prefix, controller.getTypes(), controller.getElements(), controller.getElementUtilities().getLocalMembersAndVars(scope, acceptor), isConst, csPrefix, csSuffix, preferLong))
2799
                        results.add(JavaCompletionItem.createVariableItem(env.getController(), name, anchorOffset, true, false));
2826
                        results.add(JavaCompletionItem.createVariableItem(env.getController(), name, anchorOffset, true, false));
2800
                    break;
2827
                    break;
2801
                case ENUM_CONSTANT:
2828
                case ENUM_CONSTANT:
Lines 4145-4158 Link Here
4145
                for (VariableElement variableElement : ElementFilter.fieldsIn(members)) {
4172
                for (VariableElement variableElement : ElementFilter.fieldsIn(members)) {
4146
                    Name name = variableElement.getSimpleName();
4173
                    Name name = variableElement.getSimpleName();
4147
                    if (!name.contentEquals(ERROR)) {
4174
                    if (!name.contentEquals(ERROR)) {
4148
                        String nameBase = GeneratorUtils.getCapitalizedName(name).toString();
4175
                        boolean isStatic = variableElement.getModifiers().contains(Modifier.STATIC);
4149
                        String setterName = "set" + nameBase; //NOI18N
4176
                        String setterName = CodeStyleUtils.computeSetterName(name, isStatic, codeStyle);
4150
                        String getterName = (variableElement.asType().getKind() == TypeKind.BOOLEAN ? "is" : "get") + nameBase; //NOI18N
4177
                        String getterName = CodeStyleUtils.computeGetterName(name, variableElement.asType().getKind() == TypeKind.BOOLEAN, isStatic, codeStyle);
4151
                        if ((prefix == null || startsWith(env, getterName)) && !GeneratorUtils.hasGetter(controller, te, variableElement, methods)) {
4178
                        if ((prefix == null || startsWith(env, getterName)) && !GeneratorUtils.hasGetter(controller, te, variableElement, methods, codeStyle)) {
4152
                            results.add(JavaCompletionItem.createGetterSetterMethodItem(env.getController(), variableElement, asMemberOf(variableElement, clsType, types), anchorOffset, false));
4179
                            results.add(JavaCompletionItem.createGetterSetterMethodItem(env.getController(), variableElement, asMemberOf(variableElement, clsType, types), anchorOffset, getterName, false));
4153
                        }
4180
                        }
4154
                        if ((prefix == null || startsWith(env, setterName)) && !(variableElement.getModifiers().contains(Modifier.FINAL) || GeneratorUtils.hasSetter(controller, te, variableElement, methods))) {
4181
                        if ((prefix == null || startsWith(env, setterName)) && !(variableElement.getModifiers().contains(Modifier.FINAL) || GeneratorUtils.hasSetter(controller, te, variableElement, methods, codeStyle))) {
4155
                            results.add(JavaCompletionItem.createGetterSetterMethodItem(env.getController(), variableElement, asMemberOf(variableElement, clsType, types), anchorOffset, true));
4182
                            results.add(JavaCompletionItem.createGetterSetterMethodItem(env.getController(), variableElement, asMemberOf(variableElement, clsType, types), anchorOffset, setterName, true));
4156
                        }
4183
                        }
4157
                    }
4184
                    }
4158
                }
4185
                }
(-)a/java.editor/src/org/netbeans/modules/editor/java/Utilities.java (-5 / +7 lines)
Lines 82-87 Link Here
82
import org.netbeans.api.editor.mimelookup.MimeLookup;
82
import org.netbeans.api.editor.mimelookup.MimeLookup;
83
import org.netbeans.api.editor.settings.SimpleValueNames;
83
import org.netbeans.api.editor.settings.SimpleValueNames;
84
import org.netbeans.api.java.lexer.JavaTokenId;
84
import org.netbeans.api.java.lexer.JavaTokenId;
85
import org.netbeans.api.java.source.CodeStyleUtils;
85
import org.netbeans.api.java.source.CompilationInfo;
86
import org.netbeans.api.java.source.CompilationInfo;
86
import org.netbeans.api.java.source.ElementHandle;
87
import org.netbeans.api.java.source.ElementHandle;
87
import org.netbeans.api.java.source.SourceUtils;
88
import org.netbeans.api.java.source.SourceUtils;
Lines 530-536 Link Here
530
        return refs;
531
        return refs;
531
    }
532
    }
532
    
533
    
533
    public static List<String> varNamesSuggestions(TypeMirror type, String suggestedName, String prefix, Types types, Elements elements, Iterable<? extends Element> locals, boolean isConst) {
534
    public static List<String> varNamesSuggestions(TypeMirror type, String suggestedName, String prefix, Types types, Elements elements, Iterable<? extends Element> locals, boolean isConst, String namePrefix, String nameSuffix, Boolean preferLong) {
534
        List<String> result = new ArrayList<String>();
535
        List<String> result = new ArrayList<String>();
535
        if (type == null && suggestedName == null)
536
        if (type == null && suggestedName == null)
536
            return result;
537
            return result;
Lines 566-579 Link Here
566
            }
567
            }
567
            int cnt = 1;
568
            int cnt = 1;
568
            String baseName = name;
569
            String baseName = name;
570
            name = CodeStyleUtils.addPrefixSuffix(name, namePrefix, nameSuffix);
569
            while (isClashing(name, type, locals)) {
571
            while (isClashing(name, type, locals)) {
570
                if (isPrimitive) {
572
                if (isPrimitive) {
571
                    char c = name.charAt(0);
573
                    char c = name.charAt(namePrefix != null?namePrefix.length():0);
572
                    name = Character.toString(++c);
574
                    name = CodeStyleUtils.addPrefixSuffix(Character.toString(++c), namePrefix, nameSuffix);
573
                    if (c == 'z') //NOI18N
575
                    if (c == 'z' || c == 'Z') //NOI18N
574
                        isPrimitive = false;
576
                        isPrimitive = false;
575
                } else {
577
                } else {
576
                    name = baseName + cnt++;
578
                    name = CodeStyleUtils.addPrefixSuffix(baseName + cnt++, namePrefix, nameSuffix);
577
                }
579
                }
578
            }
580
            }
579
            result.add(name);
581
            result.add(name);
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/GeneratorUtils.java (-23 / +9 lines)
Lines 88-93 Link Here
88
88
89
import org.netbeans.api.annotations.common.NonNull;
89
import org.netbeans.api.annotations.common.NonNull;
90
import org.netbeans.api.java.source.CodeStyle;
90
import org.netbeans.api.java.source.CodeStyle;
91
import org.netbeans.api.java.source.CodeStyleUtils;
91
import org.netbeans.api.java.source.Comment;
92
import org.netbeans.api.java.source.Comment;
92
import org.netbeans.api.java.source.CompilationInfo;
93
import org.netbeans.api.java.source.CompilationInfo;
93
import org.netbeans.api.java.source.ElementUtilities;
94
import org.netbeans.api.java.source.ElementUtilities;
Lines 275-288 Link Here
275
        }
276
        }
276
    }
277
    }
277
    
278
    
278
    public static boolean hasGetter(CompilationInfo info, TypeElement typeElement, VariableElement field, Map<String, List<ExecutableElement>> methods) {
279
    public static boolean hasGetter(CompilationInfo info, TypeElement typeElement, VariableElement field, Map<String, List<ExecutableElement>> methods, CodeStyle cs) {
279
        CharSequence name = field.getSimpleName();
280
        CharSequence name = field.getSimpleName();
280
        assert name.length() > 0;
281
        assert name.length() > 0;
281
        TypeMirror type = field.asType();
282
        TypeMirror type = field.asType();
282
        StringBuilder sb = getCapitalizedName(name);
283
        boolean isStatic = field.getModifiers().contains(Modifier.STATIC);
283
        sb.insert(0, type.getKind() == TypeKind.BOOLEAN ? "is" : "get"); //NOI18N
284
        String getterName = CodeStyleUtils.computeGetterName(name, type.getKind() == TypeKind.BOOLEAN, isStatic, cs);
284
        Types types = info.getTypes();
285
        Types types = info.getTypes();
285
        List<ExecutableElement> candidates = methods.get(sb.toString());
286
        List<ExecutableElement> candidates = methods.get(getterName);
286
        if (candidates != null) {
287
        if (candidates != null) {
287
            for (ExecutableElement candidate : candidates) {
288
            for (ExecutableElement candidate : candidates) {
288
                if ((!candidate.getModifiers().contains(Modifier.ABSTRACT) || candidate.getEnclosingElement() == typeElement)
289
                if ((!candidate.getModifiers().contains(Modifier.ABSTRACT) || candidate.getEnclosingElement() == typeElement)
Lines 294-307 Link Here
294
        return false;
295
        return false;
295
    }
296
    }
296
    
297
    
297
    public static boolean hasSetter(CompilationInfo info, TypeElement typeElement, VariableElement field, Map<String, List<ExecutableElement>> methods) {
298
    public static boolean hasSetter(CompilationInfo info, TypeElement typeElement, VariableElement field, Map<String, List<ExecutableElement>> methods, CodeStyle cs) {
298
        CharSequence name = field.getSimpleName();
299
        CharSequence name = field.getSimpleName();
299
        assert name.length() > 0;
300
        assert name.length() > 0;
300
        TypeMirror type = field.asType();
301
        TypeMirror type = field.asType();
301
        StringBuilder sb = getCapitalizedName(name);
302
        boolean isStatic = field.getModifiers().contains(Modifier.STATIC);
302
        sb.insert(0, "set"); //NOI18N
303
        String setterName = CodeStyleUtils.computeSetterName(name, isStatic, cs);
303
        Types types = info.getTypes();
304
        Types types = info.getTypes();
304
        List<ExecutableElement> candidates = methods.get(sb.toString());
305
        List<ExecutableElement> candidates = methods.get(setterName);
305
        if (candidates != null) {
306
        if (candidates != null) {
306
            for (ExecutableElement candidate : candidates) {
307
            for (ExecutableElement candidate : candidates) {
307
                if ((!candidate.getModifiers().contains(Modifier.ABSTRACT) || candidate.getEnclosingElement() == typeElement)
308
                if ((!candidate.getModifiers().contains(Modifier.ABSTRACT) || candidate.getEnclosingElement() == typeElement)
Lines 596-616 Link Here
596
        }
597
        }
597
        return ((PackageElement) e.getEnclosingElement()).getQualifiedName().toString();
598
        return ((PackageElement) e.getEnclosingElement()).getQualifiedName().toString();
598
    }
599
    }
599
    
600
    public static StringBuilder getCapitalizedName(CharSequence cs) {
601
        StringBuilder sb = new StringBuilder(cs);
602
        while(sb.length() > 1 && sb.charAt(0) == '_') //NOI18N
603
            sb.deleteCharAt(0);
604
        
605
        //Beans naming convention, #165241
606
        if (sb.length() > 1 && Character.isUpperCase(sb.charAt(1))) {
607
            return sb;
608
        }
609
610
        if (sb.length() > 0)
611
            sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
612
        return sb;
613
    }
614
600
615
    public static void guardedCommit(JTextComponent component, ModificationResult mr) throws IOException {
601
    public static void guardedCommit(JTextComponent component, ModificationResult mr) throws IOException {
616
        try {
602
        try {
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/GetterSetterGenerator.java (-10 / +14 lines)
Lines 92-97 Link Here
92
        public List<? extends CodeGenerator> create(Lookup context) {
92
        public List<? extends CodeGenerator> create(Lookup context) {
93
            ArrayList<CodeGenerator> ret = new ArrayList<CodeGenerator>();
93
            ArrayList<CodeGenerator> ret = new ArrayList<CodeGenerator>();
94
            JTextComponent component = context.lookup(JTextComponent.class);
94
            JTextComponent component = context.lookup(JTextComponent.class);
95
            CodeStyle codeStyle = CodeStyle.getDefault(component.getDocument());
95
            CompilationController controller = context.lookup(CompilationController.class);
96
            CompilationController controller = context.lookup(CompilationController.class);
96
            TreePath path = context.lookup(TreePath.class);
97
            TreePath path = context.lookup(TreePath.class);
97
            path = path != null ? Utilities.getPathElementOfKind(TreeUtilities.CLASS_TREE_KINDS, path) : null;
98
            path = path != null ? Utilities.getPathElementOfKind(TreeUtilities.CLASS_TREE_KINDS, path) : null;
Lines 122-129 Link Here
122
                if (ERROR.contentEquals(variableElement.getSimpleName()))
123
                if (ERROR.contentEquals(variableElement.getSimpleName()))
123
                    continue;
124
                    continue;
124
                ElementNode.Description description = ElementNode.Description.create(controller, variableElement, null, true, false);
125
                ElementNode.Description description = ElementNode.Description.create(controller, variableElement, null, true, false);
125
                boolean hasGetter = GeneratorUtils.hasGetter(controller, typeElement, variableElement, methods);
126
                boolean hasGetter = GeneratorUtils.hasGetter(controller, typeElement, variableElement, methods, codeStyle);
126
                boolean hasSetter = variableElement.getModifiers().contains(Modifier.FINAL) || GeneratorUtils.hasSetter(controller, typeElement, variableElement, methods);
127
                boolean hasSetter = variableElement.getModifiers().contains(Modifier.FINAL) || GeneratorUtils.hasSetter(controller, typeElement, variableElement, methods, codeStyle);
127
                if (!hasGetter) {
128
                if (!hasGetter) {
128
                    List<ElementNode.Description> descriptions = gDescriptions.get(variableElement.getEnclosingElement());
129
                    List<ElementNode.Description> descriptions = gDescriptions.get(variableElement.getEnclosingElement());
129
                    if (descriptions == null) {
130
                    if (descriptions == null) {
Lines 154-174 Link Here
154
                for (Map.Entry<Element, List<ElementNode.Description>> entry : gDescriptions.entrySet())
155
                for (Map.Entry<Element, List<ElementNode.Description>> entry : gDescriptions.entrySet())
155
                    descriptions.add(ElementNode.Description.create(controller, entry.getKey(), entry.getValue(), false, false));
156
                    descriptions.add(ElementNode.Description.create(controller, entry.getKey(), entry.getValue(), false, false));
156
                Collections.reverse(descriptions);
157
                Collections.reverse(descriptions);
157
                ret.add(new GetterSetterGenerator(component, ElementNode.Description.create(controller, typeElement, descriptions, false, false), GeneratorUtils.GETTERS_ONLY));
158
                ret.add(new GetterSetterGenerator(component, ElementNode.Description.create(controller, typeElement, descriptions, false, false), GeneratorUtils.GETTERS_ONLY, codeStyle));
158
            }
159
            }
159
            if (!sDescriptions.isEmpty()) {
160
            if (!sDescriptions.isEmpty()) {
160
                List<ElementNode.Description> descriptions = new ArrayList<ElementNode.Description>();
161
                List<ElementNode.Description> descriptions = new ArrayList<ElementNode.Description>();
161
                for (Map.Entry<Element, List<ElementNode.Description>> entry : sDescriptions.entrySet())
162
                for (Map.Entry<Element, List<ElementNode.Description>> entry : sDescriptions.entrySet())
162
                    descriptions.add(ElementNode.Description.create(controller, entry.getKey(), entry.getValue(), false, false));
163
                    descriptions.add(ElementNode.Description.create(controller, entry.getKey(), entry.getValue(), false, false));
163
                Collections.reverse(descriptions);
164
                Collections.reverse(descriptions);
164
                ret.add(new GetterSetterGenerator(component, ElementNode.Description.create(controller, typeElement, descriptions, false, false), GeneratorUtils.SETTERS_ONLY));
165
                ret.add(new GetterSetterGenerator(component, ElementNode.Description.create(controller, typeElement, descriptions, false, false), GeneratorUtils.SETTERS_ONLY, codeStyle));
165
            }
166
            }
166
            if (!gsDescriptions.isEmpty()) {
167
            if (!gsDescriptions.isEmpty()) {
167
                List<ElementNode.Description> descriptions = new ArrayList<ElementNode.Description>();
168
                List<ElementNode.Description> descriptions = new ArrayList<ElementNode.Description>();
168
                for (Map.Entry<Element, List<ElementNode.Description>> entry : gsDescriptions.entrySet())
169
                for (Map.Entry<Element, List<ElementNode.Description>> entry : gsDescriptions.entrySet())
169
                    descriptions.add(ElementNode.Description.create(controller, entry.getKey(), entry.getValue(), false, false));
170
                    descriptions.add(ElementNode.Description.create(controller, entry.getKey(), entry.getValue(), false, false));
170
                Collections.reverse(descriptions);
171
                Collections.reverse(descriptions);
171
                ret.add(new GetterSetterGenerator(component, ElementNode.Description.create(controller, typeElement, descriptions, false, false), 0));
172
                ret.add(new GetterSetterGenerator(component, ElementNode.Description.create(controller, typeElement, descriptions, false, false), 0, codeStyle));
172
            }
173
            }
173
            return ret;
174
            return ret;
174
        }
175
        }
Lines 177-188 Link Here
177
    private JTextComponent component;
178
    private JTextComponent component;
178
    private ElementNode.Description description;
179
    private ElementNode.Description description;
179
    private int type;
180
    private int type;
181
    private CodeStyle codestyle;
180
182
181
    /** Creates a new instance of GetterSetterGenerator */
183
    /** Creates a new instance of GetterSetterGenerator */
182
    private GetterSetterGenerator(JTextComponent component, ElementNode.Description description, int type) {
184
    private GetterSetterGenerator(JTextComponent component, ElementNode.Description description, int type, CodeStyle codeStyle) {
183
        this.component = component;
185
        this.component = component;
184
        this.description = description;
186
        this.description = description;
185
        this.type = type;
187
        this.type = type;
188
        this.codestyle = codeStyle;
186
    }
189
    }
187
190
188
    public String getDisplayName() {
191
    public String getDisplayName() {
Lines 256-262 Link Here
256
259
257
                @Override
260
                @Override
258
                public void run(CompilationController parameter) throws Exception {
261
                public void run(CompilationController parameter) throws Exception {
259
                    createGetterSetterLists(parameter, variables, getters, setters);
262
                    createGetterSetterLists(parameter, variables, getters, setters, codestyle);
260
                }
263
                }
261
            }, true);
264
            }, true);
262
            
265
            
Lines 277-291 Link Here
277
280
278
    }
281
    }
279
        
282
        
280
    private void createGetterSetterLists(CompilationController cc, List<ElementHandle<? extends Element>> variables, List<String> getters, List<String> setters) {
283
    private void createGetterSetterLists(CompilationController cc, List<ElementHandle<? extends Element>> variables, List<String> getters, List<String> setters, CodeStyle codestyle) {
281
        for (ElementHandle handle:variables) {
284
        for (ElementHandle handle:variables) {
282
            final Element el = handle.resolve(cc);
285
            final Element el = handle.resolve(cc);
286
            boolean isStatic = el.getModifiers().contains(Modifier.STATIC);
283
            if (type!=GeneratorUtils.GETTERS_ONLY)
287
            if (type!=GeneratorUtils.GETTERS_ONLY)
284
                setters.add("set" + GeneratorUtils.getCapitalizedName(el.getSimpleName()));//NOI18N
288
                setters.add(CodeStyleUtils.computeSetterName(el.getSimpleName(), isStatic, codestyle));
285
            else 
289
            else 
286
                setters.add(null);
290
                setters.add(null);
287
            if (type!=GeneratorUtils.SETTERS_ONLY)
291
            if (type!=GeneratorUtils.SETTERS_ONLY)
288
                getters.add((el.asType().getKind() == TypeKind.BOOLEAN ? "is" : "get") + GeneratorUtils.getCapitalizedName(el.getSimpleName()));//NOI18N
292
                getters.add(CodeStyleUtils.computeGetterName(el.getSimpleName(), el.asType().getKind() == TypeKind.BOOLEAN, isStatic, codestyle));
289
            else
293
            else
290
                getters.add(null);
294
                getters.add(null);
291
        }
295
        }
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/LoggerGenerator.java (-1 / +3 lines)
Lines 72-77 Link Here
72
import com.sun.source.tree.Scope;
72
import com.sun.source.tree.Scope;
73
import com.sun.source.tree.VariableTree;
73
import com.sun.source.tree.VariableTree;
74
import com.sun.source.util.TreePath;
74
import com.sun.source.util.TreePath;
75
import org.netbeans.api.java.source.CodeStyle;
75
76
76
import org.netbeans.api.java.source.CompilationController;
77
import org.netbeans.api.java.source.CompilationController;
77
import org.netbeans.api.java.source.GeneratorUtilities;
78
import org.netbeans.api.java.source.GeneratorUtilities;
Lines 160-166 Link Here
160
                            org.netbeans.editor.Utilities.setStatusBoldText(component, message);
161
                            org.netbeans.editor.Utilities.setStatusBoldText(component, message);
161
                        } else {
162
                        } else {
162
                            ClassTree cls = (ClassTree) path.getLeaf();
163
                            ClassTree cls = (ClassTree) path.getLeaf();
163
                            List<String> names = Utilities.varNamesSuggestions(null, "LOG", null, copy.getTypes(), copy.getElements(), e.getEnclosedElements(), true);
164
                            CodeStyle cs = CodeStyle.getDefault(component.getDocument());
165
                            List<String> names = Utilities.varNamesSuggestions(null, "LOG", null, copy.getTypes(), copy.getElements(), e.getEnclosedElements(), true, cs.getStaticFieldNamePrefix(), cs.getStaticFieldNameSuffix(), cs.preferLongerNames());
164
                            VariableTree var = createLoggerField(copy.getTreeMaker(), cls, names.size() > 0 ? names.get(0) : "LOG"); //NOI18N
166
                            VariableTree var = createLoggerField(copy.getTreeMaker(), cls, names.size() > 0 ? names.get(0) : "LOG"); //NOI18N
165
                            copy.rewrite(cls, GeneratorUtils.insertClassMembers(copy, cls, Collections.singletonList(var), caretOffset));
167
                            copy.rewrite(cls, GeneratorUtils.insertClassMembers(copy, cls, Collections.singletonList(var), caretOffset));
166
                        }
168
                        }
(-)a/java.editor/src/org/netbeans/modules/java/editor/rename/InstantRenamePerformer.java (-2 / +32 lines)
Lines 59-67 Link Here
59
import java.util.ArrayList;
59
import java.util.ArrayList;
60
import java.util.Collections;
60
import java.util.Collections;
61
import java.util.EnumSet;
61
import java.util.EnumSet;
62
import java.util.HashMap;
62
import java.util.HashSet;
63
import java.util.HashSet;
63
import java.util.LinkedHashSet;
64
import java.util.LinkedHashSet;
64
import java.util.List;
65
import java.util.List;
66
import java.util.Map;
65
import java.util.Set;
67
import java.util.Set;
66
import java.util.logging.Level;
68
import java.util.logging.Level;
67
import java.util.logging.Logger;
69
import java.util.logging.Logger;
Lines 71-76 Link Here
71
import javax.lang.model.element.Modifier;
73
import javax.lang.model.element.Modifier;
72
import javax.lang.model.element.Name;
74
import javax.lang.model.element.Name;
73
import javax.lang.model.element.TypeElement;
75
import javax.lang.model.element.TypeElement;
76
import javax.lang.model.element.VariableElement;
74
import javax.lang.model.util.ElementFilter;
77
import javax.lang.model.util.ElementFilter;
75
import javax.lang.model.util.ElementScanner6;
78
import javax.lang.model.util.ElementScanner6;
76
import javax.swing.Action;
79
import javax.swing.Action;
Lines 99-104 Link Here
99
import org.netbeans.api.editor.settings.FontColorSettings;
102
import org.netbeans.api.editor.settings.FontColorSettings;
100
import org.netbeans.api.java.lexer.JavaTokenId;
103
import org.netbeans.api.java.lexer.JavaTokenId;
101
import org.netbeans.api.java.lexer.JavadocTokenId;
104
import org.netbeans.api.java.lexer.JavadocTokenId;
105
import org.netbeans.api.java.source.CodeStyle;
102
import org.netbeans.api.java.source.CompilationInfo;
106
import org.netbeans.api.java.source.CompilationInfo;
103
import org.netbeans.api.java.source.ElementUtilities;
107
import org.netbeans.api.java.source.ElementUtilities;
104
import org.netbeans.api.java.source.JavaSource;
108
import org.netbeans.api.java.source.JavaSource;
Lines 115-120 Link Here
115
import org.netbeans.modules.editor.java.ComputeOffAWT;
119
import org.netbeans.modules.editor.java.ComputeOffAWT;
116
import org.netbeans.modules.editor.java.ComputeOffAWT.Worker;
120
import org.netbeans.modules.editor.java.ComputeOffAWT.Worker;
117
import org.netbeans.modules.editor.java.JavaKit;
121
import org.netbeans.modules.editor.java.JavaKit;
122
import org.netbeans.modules.java.editor.codegen.GeneratorUtils;
118
import org.netbeans.modules.java.editor.javadoc.JavadocImports;
123
import org.netbeans.modules.java.editor.javadoc.JavadocImports;
119
import org.netbeans.modules.java.editor.semantic.FindLocalUsagesQuery;
124
import org.netbeans.modules.java.editor.semantic.FindLocalUsagesQuery;
120
import org.netbeans.modules.refactoring.api.AbstractRefactoring;
125
import org.netbeans.modules.refactoring.api.AbstractRefactoring;
Lines 380-386 Link Here
380
            el = el.getEnclosingElement();
385
            el = el.getEnclosingElement();
381
        }
386
        }
382
        
387
        
383
        if (allowInstantRename(el, info.getElementUtilities())) {
388
        if (allowInstantRename(info, el, info.getElementUtilities())) {
384
            final Set<Token> points = new HashSet<Token>(new FindLocalUsagesQuery(true).findUsages(el, info, doc));
389
            final Set<Token> points = new HashSet<Token>(new FindLocalUsagesQuery(true).findUsages(el, info, doc));
385
            
390
            
386
            if (el.getKind().isClass()) {
391
            if (el.getKind().isClass()) {
Lines 445-451 Link Here
445
        return result;
450
        return result;
446
    }
451
    }
447
452
448
    private static boolean allowInstantRename(Element e, ElementUtilities eu) {
453
    private static boolean allowInstantRename(CompilationInfo info, Element e, ElementUtilities eu) {
454
        if(e.getKind() == ElementKind.FIELD) {
455
            VariableElement variableElement = (VariableElement) e;
456
            TypeElement typeElement = eu.enclosingTypeElement(e);
457
            Map<String, List<ExecutableElement>> methods = new HashMap<String, List<ExecutableElement>>();
458
            for (ExecutableElement method : ElementFilter.methodsIn(info.getElements().getAllMembers(typeElement))) {
459
                List<ExecutableElement> l = methods.get(method.getSimpleName().toString());
460
                if (l == null) {
461
                    l = new ArrayList<ExecutableElement>();
462
                    methods.put(method.getSimpleName().toString(), l);
463
                }
464
                l.add(method);
465
            }
466
            
467
            boolean isProperty = false;
468
            try {
469
                CodeStyle codeStyle = CodeStyle.getDefault(info.getDocument());
470
                isProperty = GeneratorUtils.hasGetter(info, typeElement, variableElement, methods, codeStyle);
471
                isProperty = isProperty || (!variableElement.getModifiers().contains(Modifier.FINAL) &&
472
                                    GeneratorUtils.hasSetter(info, typeElement, variableElement, methods, codeStyle));
473
            } catch (IOException ex) {
474
            }
475
            if(isProperty) {
476
                return false;
477
            }
478
        }
449
        if (org.netbeans.modules.java.editor.semantic.Utilities.isPrivateElement(e)) {
479
        if (org.netbeans.modules.java.editor.semantic.Utilities.isPrivateElement(e)) {
450
            return true;
480
            return true;
451
        }
481
        }
(-)a/java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java (-9 / +28 lines)
Lines 155-160 Link Here
155
    }
155
    }
156
156
157
    public static String guessName(CompilationInfo info, TreePath tp, TreePath scope) {
157
    public static String guessName(CompilationInfo info, TreePath tp, TreePath scope) {
158
        return guessName(info, tp, scope, null, null);
159
    }
160
161
    public static String guessName(CompilationInfo info, TreePath tp, TreePath scope, String prefix, String suffix) {
158
        String name = getName(tp.getLeaf());
162
        String name = getName(tp.getLeaf());
159
        
163
        
160
        if (name == null) {
164
        if (name == null) {
Lines 163-178 Link Here
163
        
167
        
164
        Scope s = info.getTrees().getScope(scope);
168
        Scope s = info.getTrees().getScope(scope);
165
        
169
        
166
        return makeNameUnique(info, s, name);
170
        return makeNameUnique(info, s, name, prefix, suffix);
167
    }
171
    }
168
172
    
169
    public static String makeNameUnique(CompilationInfo info, Scope s, String name) {
173
    public static String makeNameUnique(CompilationInfo info, Scope s, String name, String prefix, String suffix) {
174
        if(prefix != null && prefix.length() > 0) {
175
            if(Character.isAlphabetic(prefix.charAt(prefix.length()-1))) {
176
                StringBuilder nameSb = new StringBuilder(name);
177
                nameSb.setCharAt(0, Character.toUpperCase(nameSb.charAt(0)));
178
                name = nameSb.toString();
179
            }
180
        }
181
        
182
        boolean cont;
183
        String proposedName;
170
        int counter = 0;
184
        int counter = 0;
171
        boolean cont = true;
185
        do {
172
        String proposedName = name;
186
            proposedName = safeString(prefix) + name + (counter != 0 ? String.valueOf(counter) : "") + safeString(suffix);
173
        
174
        while (cont) {
175
            proposedName = name + (counter != 0 ? String.valueOf(counter) : "");
176
            
187
            
177
            cont = false;
188
            cont = false;
178
            
189
            
Lines 183-192 Link Here
183
                    break;
194
                    break;
184
                }
195
                }
185
            }
196
            }
186
        }
197
        } while(cont);
187
        
198
        
188
        return proposedName;
199
        return proposedName;
189
    }
200
    }
201
    
202
    private static String safeString(String str) {
203
        return str == null ? "" : str;
204
    }
205
206
    public static String makeNameUnique(CompilationInfo info, Scope s, String name) {
207
        return makeNameUnique(info, s, name, null, null);
208
    }
190
209
191
    private static String guessLiteralName(String str) {
210
    private static String guessLiteralName(String str) {
192
        if(str.isEmpty())
211
        if(str.isEmpty())
(-)a/java.hints/src/org/netbeans/modules/java/hints/introduce/IntroduceHint.java (-3 / +8 lines)
Lines 116-121 Link Here
116
import org.netbeans.api.editor.settings.AttributesUtilities;
116
import org.netbeans.api.editor.settings.AttributesUtilities;
117
import org.netbeans.api.java.lexer.JavaTokenId;
117
import org.netbeans.api.java.lexer.JavaTokenId;
118
import org.netbeans.api.java.source.CancellableTask;
118
import org.netbeans.api.java.source.CancellableTask;
119
import org.netbeans.api.java.source.CodeStyle;
119
import org.netbeans.api.java.source.Task;
120
import org.netbeans.api.java.source.Task;
120
import org.netbeans.api.java.source.CompilationInfo;
121
import org.netbeans.api.java.source.CompilationInfo;
121
import org.netbeans.api.java.source.GeneratorUtilities;
122
import org.netbeans.api.java.source.GeneratorUtilities;
Lines 443-450 Link Here
443
            String guessedName = Utilities.getName(resolved.getLeaf());
444
            String guessedName = Utilities.getName(resolved.getLeaf());
444
            if (guessedName == null) guessedName = "name";
445
            if (guessedName == null) guessedName = "name";
445
            Scope s = info.getTrees().getScope(resolved);
446
            Scope s = info.getTrees().getScope(resolved);
446
            Fix variable = isVariable ? new IntroduceFix(h, info.getJavaSource(), variableRewrite ? guessedName : Utilities.makeNameUnique(info, s, guessedName), duplicatesForVariable.size() + 1, IntroduceKind.CREATE_VARIABLE) : null;
447
            CodeStyle cs = CodeStyle.getDefault(info.getFileObject());
447
            Fix constant = isConstant ? new IntroduceFix(h, info.getJavaSource(), variableRewrite ? guessedName : Utilities.makeNameUnique(info, info.getTrees().getScope(constantTarget), Utilities.toConstantName(guessedName)), duplicatesForConstant.size() + 1, IntroduceKind.CREATE_CONSTANT) : null;
448
            Fix variable = isVariable ? new IntroduceFix(h, info.getJavaSource(), variableRewrite ? guessedName : Utilities.makeNameUnique(info, s, guessedName, cs.getLocalVarNamePrefix(), cs.getLocalVarNameSuffix()), duplicatesForVariable.size() + 1, IntroduceKind.CREATE_VARIABLE) : null;
449
            Fix constant = isConstant ? new IntroduceFix(h, info.getJavaSource(), variableRewrite ? guessedName : Utilities.makeNameUnique(info, info.getTrees().getScope(constantTarget), Utilities.toConstantName(guessedName), cs.getStaticFieldNamePrefix(), cs.getStaticFieldNameSuffix()), duplicatesForConstant.size() + 1, IntroduceKind.CREATE_CONSTANT) : null;
448
            Fix parameter = isVariable ? new IntroduceParameterFix(h) : null;
450
            Fix parameter = isVariable ? new IntroduceParameterFix(h) : null;
449
            Fix field = null;
451
            Fix field = null;
450
            Fix methodFix = null;
452
            Fix methodFix = null;
Lines 466-472 Link Here
466
468
467
                if (resolved.getLeaf().getKind() == Kind.VARIABLE) {
469
                if (resolved.getLeaf().getKind() == Kind.VARIABLE) {
468
                    //the variable name would incorrectly clash with itself:
470
                    //the variable name would incorrectly clash with itself:
469
                    guessedName = Utilities.guessName(info, resolved, resolved.getParentPath());
471
                    guessedName = Utilities.guessName(info, resolved, resolved.getParentPath(), cs.getFieldNamePrefix(), cs.getFieldNameSuffix());
472
                } else if (!variableRewrite) {
473
                    guessedName = Utilities.makeNameUnique(info, info.getTrees().getScope(constantTarget),
474
                            guessedName, cs.getFieldNamePrefix(), cs.getFieldNameSuffix());
470
                }
475
                }
471
476
472
                field = new IntroduceFieldFix(h, info.getJavaSource(), guessedName, duplicatesForConstant.size() + 1, initilizeIn, statik, allowFinalInCurrentMethod);
477
                field = new IntroduceFieldFix(h, info.getJavaSource(), guessedName, duplicatesForConstant.size() + 1, initilizeIn, statik, allowFinalInCurrentMethod);
(-)a/java.hints/test/unit/src/org/netbeans/modules/java/hints/introduce/IntroduceHintTest.java (-1 / +2 lines)
Lines 56-61 Link Here
56
import javax.lang.model.element.Modifier;
56
import javax.lang.model.element.Modifier;
57
import javax.swing.text.Document;
57
import javax.swing.text.Document;
58
import org.netbeans.api.java.lexer.JavaTokenId;
58
import org.netbeans.api.java.lexer.JavaTokenId;
59
import org.netbeans.api.java.source.CodeStyle;
59
import org.netbeans.api.java.source.CompilationInfo;
60
import org.netbeans.api.java.source.CompilationInfo;
60
import org.netbeans.api.java.source.JavaSource;
61
import org.netbeans.api.java.source.JavaSource;
61
import org.netbeans.api.java.source.JavaSource.Phase;
62
import org.netbeans.api.java.source.JavaSource.Phase;
Lines 666-672 Link Here
666
                .<Modifier>of(Modifier.PRIVATE), false, true),
667
                .<Modifier>of(Modifier.PRIVATE), false, true),
667
                       5, 2);
668
                       5, 2);
668
    }
669
    }
669
670
    
670
    public void testFix21() throws Exception {
671
    public void testFix21() throws Exception {
671
        performFixTest("package test; import java.util.List; public class Test {public void test1() {List<? extends CharSequence> l = |test()|;} public List<? extends CharSequence> test() {return null;}}",
672
        performFixTest("package test; import java.util.List; public class Test {public void test1() {List<? extends CharSequence> l = |test()|;} public List<? extends CharSequence> test() {return null;}}",
672
                       "package test; import java.util.List; public class Test { private List<? extends CharSequence> name; public void test1() {name = test(); List<? extends CharSequence> l = name;} public List<? extends CharSequence> test() {return null;}}",
673
                       "package test; import java.util.List; public class Test { private List<? extends CharSequence> name; public void test1() {name = test(); List<? extends CharSequence> l = name;} public List<? extends CharSequence> test() {return null;}}",
(-)a/java.source/src/org/netbeans/api/java/source/GeneratorUtilities.java (-48 / +54 lines)
Lines 80-92 Link Here
80
import com.sun.tools.javac.tree.JCTree;
80
import com.sun.tools.javac.tree.JCTree;
81
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
81
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
82
82
83
import java.io.ByteArrayOutputStream;
84
import java.io.IOException;
83
import java.io.IOException;
85
import java.io.InputStreamReader;
84
import java.io.InputStreamReader;
86
import java.io.OutputStreamWriter;
87
import java.io.PrintWriter;
88
import java.io.Reader;
85
import java.io.Reader;
89
import java.io.Writer;
90
import java.nio.charset.Charset;
86
import java.nio.charset.Charset;
91
import java.util.ArrayList;
87
import java.util.ArrayList;
92
import java.util.Arrays;
88
import java.util.Arrays;
Lines 471-483 Link Here
471
    public MethodTree createConstructor(ClassTree clazz, Iterable<? extends VariableTree> fields) {
467
    public MethodTree createConstructor(ClassTree clazz, Iterable<? extends VariableTree> fields) {
472
        assert clazz != null && fields != null;
468
        assert clazz != null && fields != null;
473
        TreeMaker make = copy.getTreeMaker();
469
        TreeMaker make = copy.getTreeMaker();
470
        CodeStyle cs = DiffContext.getCodeStyle(copy);
474
        Set<Modifier> mods = EnumSet.of(copy.getTreeUtilities().isEnum(clazz) ? Modifier.PRIVATE : Modifier.PUBLIC);
471
        Set<Modifier> mods = EnumSet.of(copy.getTreeUtilities().isEnum(clazz) ? Modifier.PRIVATE : Modifier.PUBLIC);
475
        List<VariableTree> parameters = new ArrayList<VariableTree>();
472
        List<VariableTree> parameters = new ArrayList<VariableTree>();
476
        List<StatementTree> statements = new ArrayList<StatementTree>();
473
        List<StatementTree> statements = new ArrayList<StatementTree>();
477
        ModifiersTree parameterModifiers = make.Modifiers(EnumSet.noneOf(Modifier.class));
474
        ModifiersTree parameterModifiers = make.Modifiers(EnumSet.noneOf(Modifier.class));
478
        for (VariableTree vt : fields) {
475
        for (VariableTree vt : fields) {
479
            parameters.add(make.Variable(parameterModifiers, vt.getName(), vt.getType(), null));
476
            String paramName = addParamPrefixSuffix(removeFieldPrefixSuffix(vt, cs), cs);
480
            statements.add(make.ExpressionStatement(make.Assignment(make.MemberSelect(make.Identifier("this"), vt.getName()), make.Identifier(vt.getName())))); //NOI18N
477
            parameters.add(make.Variable(parameterModifiers, paramName, vt.getType(), null));
478
            statements.add(make.ExpressionStatement(make.Assignment(make.MemberSelect(make.Identifier("this"), vt.getName()), make.Identifier(paramName)))); //NOI18N
481
        }
479
        }
482
        BlockTree body = make.Block(statements, false);
480
        BlockTree body = make.Block(statements, false);
483
        return make.Method(make.Modifiers(mods), "<init>", null, Collections.<TypeParameterTree> emptyList(), parameters, Collections.<ExpressionTree>emptyList(), body, null); //NOI18N
481
        return make.Method(make.Modifiers(mods), "<init>", null, Collections.<TypeParameterTree> emptyList(), parameters, Collections.<ExpressionTree>emptyList(), body, null); //NOI18N
Lines 494-509 Link Here
494
    public MethodTree createGetter(TypeElement clazz, VariableElement field) {
492
    public MethodTree createGetter(TypeElement clazz, VariableElement field) {
495
        assert clazz != null && field != null;
493
        assert clazz != null && field != null;
496
        TreeMaker make = copy.getTreeMaker();
494
        TreeMaker make = copy.getTreeMaker();
495
        CodeStyle cs = DiffContext.getCodeStyle(copy);
497
        Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC);
496
        Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC);
498
        if (field.getModifiers().contains(Modifier.STATIC))
497
        boolean isStatic = field.getModifiers().contains(Modifier.STATIC);
498
        if (isStatic) {
499
            mods.add(Modifier.STATIC);
499
            mods.add(Modifier.STATIC);
500
        CharSequence name = field.getSimpleName();
500
        }
501
        assert name.length() > 0;
502
        TypeMirror type = copy.getTypes().asMemberOf((DeclaredType)clazz.asType(), field);
501
        TypeMirror type = copy.getTypes().asMemberOf((DeclaredType)clazz.asType(), field);
503
        StringBuilder sb = getCapitalizedName(name);
502
        String getterName = CodeStyleUtils.computeGetterName(field.getSimpleName(), type.getKind() == TypeKind.BOOLEAN, isStatic, cs);
504
        sb.insert(0, type.getKind() == TypeKind.BOOLEAN ? "is" : "get"); //NOI18N
503
        BlockTree body = make.Block(Collections.singletonList(make.Return(make.Identifier(field.getSimpleName()))), false);
505
        BlockTree body = make.Block(Collections.singletonList(make.Return(make.Identifier(name))), false);
504
        return make.Method(make.Modifiers(mods), getterName, make.Type(type), Collections.<TypeParameterTree>emptyList(), Collections.<VariableTree>emptyList(), Collections.<ExpressionTree>emptyList(), body, null);
506
        return make.Method(make.Modifiers(mods), sb, make.Type(type), Collections.<TypeParameterTree>emptyList(), Collections.<VariableTree>emptyList(), Collections.<ExpressionTree>emptyList(), body, null);
507
    }
505
    }
508
506
509
    /**
507
    /**
Lines 516-531 Link Here
516
    public MethodTree createGetter(VariableTree field) {
514
    public MethodTree createGetter(VariableTree field) {
517
        assert field != null;
515
        assert field != null;
518
        TreeMaker make = copy.getTreeMaker();
516
        TreeMaker make = copy.getTreeMaker();
517
        CodeStyle cs = DiffContext.getCodeStyle(copy);
519
        Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC);
518
        Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC);
520
        if (field.getModifiers().getFlags().contains(Modifier.STATIC))
519
        boolean isStatic = field.getModifiers().getFlags().contains(Modifier.STATIC);
520
        if (isStatic) {
521
            mods.add(Modifier.STATIC);
521
            mods.add(Modifier.STATIC);
522
        CharSequence name = field.getName();
522
        }
523
        assert name.length() > 0;
524
        Tree type = field.getType();
523
        Tree type = field.getType();
525
        StringBuilder sb = getCapitalizedName(name);
524
        boolean isBoolean = type.getKind() == Tree.Kind.PRIMITIVE_TYPE && ((PrimitiveTypeTree) type).getPrimitiveTypeKind() == TypeKind.BOOLEAN;
526
        sb.insert(0, type.getKind() == Tree.Kind.PRIMITIVE_TYPE && ((PrimitiveTypeTree)type).getPrimitiveTypeKind() == TypeKind.BOOLEAN ? "is" : "get"); //NOI18N
525
        String getterName = CodeStyleUtils.computeGetterName(field.getName(), isBoolean, isStatic, cs);
527
        BlockTree body = make.Block(Collections.singletonList(make.Return(make.Identifier(name))), false);
526
        BlockTree body = make.Block(Collections.singletonList(make.Return(make.Identifier(field.getName()))), false);
528
        return make.Method(make.Modifiers(mods), sb, type, Collections.<TypeParameterTree>emptyList(), Collections.<VariableTree>emptyList(), Collections.<ExpressionTree>emptyList(), body, null);
527
        return make.Method(make.Modifiers(mods), getterName, type, Collections.<TypeParameterTree>emptyList(), Collections.<VariableTree>emptyList(), Collections.<ExpressionTree>emptyList(), body, null);
529
    }
528
    }
530
529
531
    /**
530
    /**
Lines 539-556 Link Here
539
    public MethodTree createSetter(TypeElement clazz, VariableElement field) {
538
    public MethodTree createSetter(TypeElement clazz, VariableElement field) {
540
        assert clazz != null && field != null;
539
        assert clazz != null && field != null;
541
        TreeMaker make = copy.getTreeMaker();
540
        TreeMaker make = copy.getTreeMaker();
541
        CodeStyle cs = DiffContext.getCodeStyle(copy);
542
        Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC);
542
        Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC);
543
        boolean isStatic = field.getModifiers().contains(Modifier.STATIC);
543
        boolean isStatic = field.getModifiers().contains(Modifier.STATIC);
544
        if (isStatic)
544
        if (isStatic) {
545
            mods.add(Modifier.STATIC);
545
            mods.add(Modifier.STATIC);
546
        }
546
        CharSequence name = field.getSimpleName();
547
        CharSequence name = field.getSimpleName();
547
        assert name.length() > 0;
548
        assert name.length() > 0;
548
        TypeMirror type = copy.getTypes().asMemberOf((DeclaredType)clazz.asType(), field);
549
        TypeMirror type = copy.getTypes().asMemberOf((DeclaredType)clazz.asType(), field);
549
        StringBuilder sb = getCapitalizedName(name);
550
        String setterName = CodeStyleUtils.computeSetterName(field.getSimpleName(), isStatic, cs);
550
        sb.insert(0, "set"); //NOI18N
551
        String paramName = addParamPrefixSuffix(removeFieldPrefixSuffix(field, cs), cs);
551
        List<VariableTree> params = Collections.singletonList(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), name, make.Type(type), null));
552
        List<VariableTree> params = Collections.singletonList(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), paramName, make.Type(type), null));
552
        BlockTree body = make.Block(Collections.singletonList(make.ExpressionStatement(make.Assignment(make.MemberSelect(isStatic? make.Identifier(field.getEnclosingElement().getSimpleName()) : make.Identifier("this"), name), make.Identifier(name)))), false); //NOI18N
553
        BlockTree body = make.Block(Collections.singletonList(make.ExpressionStatement(make.Assignment(make.MemberSelect(isStatic? make.Identifier(field.getEnclosingElement().getSimpleName()) : make.Identifier("this"), name), make.Identifier(paramName)))), false); //NOI18N
553
        return make.Method(make.Modifiers(mods), sb, make.Type(copy.getTypes().getNoType(TypeKind.VOID)), Collections.<TypeParameterTree>emptyList(), params, Collections.<ExpressionTree>emptyList(), body, null);
554
        return make.Method(make.Modifiers(mods), setterName, make.Type(copy.getTypes().getNoType(TypeKind.VOID)), Collections.<TypeParameterTree>emptyList(), params, Collections.<ExpressionTree>emptyList(), body, null);
554
    }
555
    }
555
556
556
    /**
557
    /**
Lines 570-580 Link Here
570
            mods.add(Modifier.STATIC);
571
            mods.add(Modifier.STATIC);
571
        CharSequence name = field.getName();
572
        CharSequence name = field.getName();
572
        assert name.length() > 0;
573
        assert name.length() > 0;
573
        StringBuilder sb = getCapitalizedName(name);
574
        CodeStyle cs = DiffContext.getCodeStyle(copy);
574
        sb.insert(0, "set"); //NOI18N
575
        String propName = removeFieldPrefixSuffix(field, cs);
575
        List<VariableTree> params = Collections.singletonList(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), name, field.getType(), null));
576
        String setterName = CodeStyleUtils.computeSetterName(field.getName(), isStatic, cs);
576
        BlockTree body = make.Block(Collections.singletonList(make.ExpressionStatement(make.Assignment(make.MemberSelect(isStatic? make.Identifier(clazz.getSimpleName()) : make.Identifier("this"), name), make.Identifier(name)))), false); //NOI18N
577
        String paramName = addParamPrefixSuffix(propName, cs);
577
        return make.Method(make.Modifiers(mods), sb, make.Type(copy.getTypes().getNoType(TypeKind.VOID)), Collections.<TypeParameterTree>emptyList(), params, Collections.<ExpressionTree>emptyList(), body, null);
578
        List<VariableTree> params = Collections.singletonList(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), paramName, field.getType(), null));
579
        BlockTree body = make.Block(Collections.singletonList(make.ExpressionStatement(make.Assignment(make.MemberSelect(isStatic? make.Identifier(clazz.getSimpleName()) : make.Identifier("this"), name), make.Identifier(paramName)))), false); //NOI18N
580
        return make.Method(make.Modifiers(mods), setterName, make.Type(copy.getTypes().getNoType(TypeKind.VOID)), Collections.<TypeParameterTree>emptyList(), params, Collections.<ExpressionTree>emptyList(), body, null);
578
    }
581
    }
579
    
582
    
580
    /**
583
    /**
Lines 1158-1180 Link Here
1158
        return info.getElements().getTypeElement("java.lang.Override") != null;
1161
        return info.getElements().getTypeElement("java.lang.Override") != null;
1159
    }
1162
    }
1160
1163
1161
    private static StringBuilder getCapitalizedName(CharSequence cs) {
1162
        StringBuilder sb = new StringBuilder(cs);
1163
        while (sb.length() > 1 && sb.charAt(0) == '_') { //NOI18N
1164
            sb.deleteCharAt(0);
1165
        }
1166
1167
        //Beans naming convention, #165241
1168
        if (sb.length() > 1 && Character.isUpperCase(sb.charAt(1))) {
1169
            return sb;
1170
        }
1171
1172
        if (sb.length() > 0) {
1173
            sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
1174
        }
1175
        return sb;
1176
    }
1177
1178
    private Tree resolveWildcard(TypeMirror type) {
1164
    private Tree resolveWildcard(TypeMirror type) {
1179
        TreeMaker make = copy.getTreeMaker();
1165
        TreeMaker make = copy.getTreeMaker();
1180
        Tree result;
1166
        Tree result;
Lines 1361-1366 Link Here
1361
        return bindings;
1347
        return bindings;
1362
    }
1348
    }
1363
1349
1350
    private static String removeFieldPrefixSuffix(VariableElement var, CodeStyle cs) {
1351
        boolean isStatic = var.getModifiers().contains(Modifier.STATIC);
1352
        return CodeStyleUtils.removePrefixSuffix(var.getSimpleName(),
1353
                isStatic ? cs.getStaticFieldNamePrefix() : cs.getFieldNamePrefix(),
1354
                isStatic ? cs.getStaticFieldNameSuffix() : cs.getFieldNameSuffix());
1355
    }
1356
1357
    private static String removeFieldPrefixSuffix(VariableTree var, CodeStyle cs) {
1358
        boolean isStatic = var.getModifiers().getFlags().contains(Modifier.STATIC);
1359
        return CodeStyleUtils.removePrefixSuffix(var.getName(),
1360
                isStatic ? cs.getStaticFieldNamePrefix() : cs.getFieldNamePrefix(),
1361
                isStatic ? cs.getStaticFieldNameSuffix() : cs.getFieldNameSuffix());
1362
    }
1363
1364
    private static String addParamPrefixSuffix(CharSequence name, CodeStyle cs) {
1365
        return CodeStyleUtils.addPrefixSuffix(name,
1366
                cs.getParameterNamePrefix(),
1367
                cs.getParameterNameSuffix());
1368
    }
1369
1364
    private static class ClassMemberComparator implements Comparator<Tree> {
1370
    private static class ClassMemberComparator implements Comparator<Tree> {
1365
1371
1366
        private CodeStyle.MemberGroups groups;
1372
        private CodeStyle.MemberGroups groups;
(-)a/java.source/src/org/netbeans/modules/java/source/resources/layer.xml (+5 lines)
Lines 224-229 Link Here
224
                          <attr name="instanceCreate" methodvalue="org.netbeans.modules.java.ui.FmtImports.getController"/>
224
                          <attr name="instanceCreate" methodvalue="org.netbeans.modules.java.ui.FmtImports.getController"/>
225
                          <attr name="position" intvalue="800"/>
225
                          <attr name="position" intvalue="800"/>
226
                      </file>
226
                      </file>
227
                      <file name="Naming.instance">
228
                          <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
229
                          <attr name="instanceCreate" methodvalue="org.netbeans.modules.java.ui.FmtNaming.getController"/>
230
                          <attr name="position" intvalue="900"/>
231
                      </file>
227
                      <file name="CodeGeneration.instance">
232
                      <file name="CodeGeneration.instance">
228
                          <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
233
                          <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
229
                          <attr name="instanceCreate" methodvalue="org.netbeans.modules.java.ui.FmtCodeGeneration.getController"/>
234
                          <attr name="instanceCreate" methodvalue="org.netbeans.modules.java.ui.FmtCodeGeneration.getController"/>
(-)a/java.source/src/org/netbeans/modules/java/ui/Bundle.properties (-1 / +6 lines)
Lines 43-49 Link Here
43
# Formating options
43
# Formating options
44
44
45
LBL_TabsAndIndents=Tabs and Indents
45
LBL_TabsAndIndents=Tabs and Indents
46
LBL_CodeGeneration=Code Generation
46
LBL_CodeGeneration=Ordering
47
LBL_Naming=Naming
47
LBL_Alignment=Alignment
48
LBL_Alignment=Alignment
48
LBL_Braces=Braces
49
LBL_Braces=Braces
49
LBL_Wrapping=Wrapping
50
LBL_Wrapping=Wrapping
Lines 527-532 Link Here
527
private String name;\
528
private String name;\
528
}
529
}
529
530
531
SAMPLE_Naming=public class ClassA {\
532
\
533
}
534
530
nlFinallyCheckBox1.text="finall&y"
535
nlFinallyCheckBox1.text="finall&y"
531
536
532
AN_Preview=Preview
537
AN_Preview=Preview
(-)a/java.source/src/org/netbeans/modules/java/ui/FmtCodeGeneration.form (-230 / +13 lines)
Lines 22-28 Link Here
22
  <Layout>
22
  <Layout>
23
    <DimensionLayout dim="0">
23
    <DimensionLayout dim="0">
24
      <Group type="103" groupAlignment="0" attributes="0">
24
      <Group type="103" groupAlignment="0" attributes="0">
25
          <Component id="jSeparator1" max="32767" attributes="0"/>
26
          <Group type="102" alignment="0" attributes="0">
25
          <Group type="102" alignment="0" attributes="0">
27
              <Group type="103" groupAlignment="0" attributes="0">
26
              <Group type="103" groupAlignment="0" attributes="0">
28
                  <Component id="otherLabel" min="-2" max="-2" attributes="0"/>
27
                  <Component id="otherLabel" min="-2" max="-2" attributes="0"/>
Lines 41-70 Link Here
41
          <Component id="jSeparator3" alignment="0" max="32767" attributes="0"/>
40
          <Component id="jSeparator3" alignment="0" max="32767" attributes="0"/>
42
          <Group type="102" attributes="0">
41
          <Group type="102" attributes="0">
43
              <Group type="103" groupAlignment="0" max="-2" attributes="0">
42
              <Group type="103" groupAlignment="0" max="-2" attributes="0">
44
                  <Component id="namingConventionsLabel" min="-2" max="-2" attributes="0"/>
45
                  <Component id="memberOrderLabel" alignment="0" min="-2" max="-2" attributes="0"/>
43
                  <Component id="memberOrderLabel" alignment="0" min="-2" max="-2" attributes="0"/>
46
                  <Group type="102" attributes="0">
44
                  <Group type="102" attributes="0">
47
                      <EmptySpace max="-2" attributes="0"/>
45
                      <EmptySpace max="-2" attributes="0"/>
48
                      <Group type="103" groupAlignment="0" max="-2" attributes="0">
46
                      <Group type="103" groupAlignment="0" attributes="0">
49
                          <Component id="isForBooleanGettersCheckBox" min="-2" max="-2" attributes="0"/>
47
                          <Component id="jScrollPane1" min="-2" pref="160" max="-2" attributes="0"/>
50
                          <Component id="preferLongerNamesCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
48
                          <Component id="jScrollPane2" alignment="0" min="-2" pref="160" max="-2" attributes="0"/>
51
                          <Component id="jPanel1" alignment="0" min="-2" pref="274" max="-2" attributes="0"/>
49
                      </Group>
52
                          <Group type="102" attributes="0">
50
                      <EmptySpace max="-2" attributes="0"/>
53
                              <Group type="103" groupAlignment="0" attributes="0">
51
                      <Group type="103" groupAlignment="0" attributes="0">
54
                                  <Component id="jScrollPane1" max="32767" attributes="0"/>
52
                          <Group type="103" alignment="0" groupAlignment="0" max="-2" attributes="0">
55
                                  <Component id="jScrollPane2" alignment="0" min="-2" pref="160" max="-2" attributes="0"/>
53
                              <Component id="downButton" min="-2" pref="108" max="-2" attributes="0"/>
56
                              </Group>
54
                              <Component id="upButton" min="-2" pref="108" max="-2" attributes="0"/>
57
                              <EmptySpace max="-2" attributes="0"/>
55
                          </Group>
58
                              <Group type="103" groupAlignment="0" attributes="0">
56
                          <Group type="103" alignment="0" groupAlignment="0" max="-2" attributes="0">
59
                                  <Group type="103" alignment="0" groupAlignment="0" max="-2" attributes="0">
57
                              <Component id="visDownButton" min="-2" pref="108" max="-2" attributes="0"/>
60
                                      <Component id="downButton" max="32767" attributes="0"/>
58
                              <Component id="visUpButton" min="-2" pref="108" max="-2" attributes="0"/>
61
                                      <Component id="upButton" min="-2" pref="108" max="-2" attributes="0"/>
62
                                  </Group>
63
                                  <Group type="103" alignment="0" groupAlignment="0" max="-2" attributes="0">
64
                                      <Component id="visDownButton" max="32767" attributes="0"/>
65
                                      <Component id="visUpButton" min="-2" pref="108" max="-2" attributes="0"/>
66
                                  </Group>
67
                              </Group>
68
                          </Group>
59
                          </Group>
69
                      </Group>
60
                      </Group>
70
                  </Group>
61
                  </Group>
Lines 84-98 Link Here
84
    <DimensionLayout dim="1">
75
    <DimensionLayout dim="1">
85
      <Group type="103" groupAlignment="0" attributes="0">
76
      <Group type="103" groupAlignment="0" attributes="0">
86
          <Group type="102" attributes="0">
77
          <Group type="102" attributes="0">
87
              <Component id="namingConventionsLabel" min="-2" max="-2" attributes="0"/>
88
              <EmptySpace max="-2" attributes="0"/>
89
              <Component id="preferLongerNamesCheckBox" min="-2" max="-2" attributes="0"/>
90
              <EmptySpace max="-2" attributes="0"/>
91
              <Component id="isForBooleanGettersCheckBox" min="-2" max="-2" attributes="0"/>
92
              <EmptySpace max="-2" attributes="0"/>
93
              <Component id="jPanel1" min="-2" max="-2" attributes="0"/>
94
              <EmptySpace max="-2" attributes="0"/>
95
              <Component id="jSeparator1" min="-2" max="-2" attributes="0"/>
96
              <EmptySpace max="-2" attributes="0"/>
78
              <EmptySpace max="-2" attributes="0"/>
97
              <Component id="otherLabel" min="-2" max="-2" attributes="0"/>
79
              <Component id="otherLabel" min="-2" max="-2" attributes="0"/>
98
              <EmptySpace max="-2" attributes="0"/>
80
              <EmptySpace max="-2" attributes="0"/>
Lines 140-344 Link Here
140
    </DimensionLayout>
122
    </DimensionLayout>
141
  </Layout>
123
  </Layout>
142
  <SubComponents>
124
  <SubComponents>
143
    <Component class="javax.swing.JLabel" name="namingConventionsLabel">
144
      <Properties>
145
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
146
          <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_Naming" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
147
        </Property>
148
      </Properties>
149
    </Component>
150
    <Component class="javax.swing.JCheckBox" name="preferLongerNamesCheckBox">
151
      <Properties>
152
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
153
          <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_PreferLongerNames" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
154
        </Property>
155
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
156
          <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
157
            <EmptyBorder bottom="0" left="0" right="0" top="0"/>
158
          </Border>
159
        </Property>
160
        <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
161
          <Insets value="[0, 0, 0, 0]"/>
162
        </Property>
163
        <Property name="opaque" type="boolean" value="false"/>
164
      </Properties>
165
    </Component>
166
    <Component class="javax.swing.JCheckBox" name="isForBooleanGettersCheckBox">
167
      <Properties>
168
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
169
          <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_UseIsForBooleanGetters" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
170
        </Property>
171
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
172
          <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
173
            <EmptyBorder bottom="0" left="0" right="0" top="0"/>
174
          </Border>
175
        </Property>
176
        <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
177
          <Insets value="[0, 0, 0, 0]"/>
178
        </Property>
179
        <Property name="opaque" type="boolean" value="false"/>
180
      </Properties>
181
    </Component>
182
    <Container class="javax.swing.JPanel" name="jPanel1">
183
184
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
185
      <SubComponents>
186
        <Component class="javax.swing.JLabel" name="prefixLabel">
187
          <Properties>
188
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
189
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_Prefix" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
190
            </Property>
191
          </Properties>
192
          <Constraints>
193
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
194
              <GridBagConstraints gridX="1" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="17" weightX="0.5" weightY="0.0"/>
195
            </Constraint>
196
          </Constraints>
197
        </Component>
198
        <Component class="javax.swing.JLabel" name="suffixLabel">
199
          <Properties>
200
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
201
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_Suffix" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
202
            </Property>
203
          </Properties>
204
          <Constraints>
205
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
206
              <GridBagConstraints gridX="2" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="17" weightX="0.5" weightY="0.0"/>
207
            </Constraint>
208
          </Constraints>
209
        </Component>
210
        <Component class="javax.swing.JLabel" name="fieldLabel">
211
          <Properties>
212
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
213
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_Field" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
214
            </Property>
215
          </Properties>
216
          <Constraints>
217
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
218
              <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
219
            </Constraint>
220
          </Constraints>
221
        </Component>
222
        <Component class="javax.swing.JTextField" name="fieldPrefixField">
223
          <Properties>
224
            <Property name="columns" type="int" value="5"/>
225
          </Properties>
226
          <Constraints>
227
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
228
              <GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
229
            </Constraint>
230
          </Constraints>
231
        </Component>
232
        <Component class="javax.swing.JTextField" name="fieldSuffixField">
233
          <Properties>
234
            <Property name="columns" type="int" value="5"/>
235
          </Properties>
236
          <Constraints>
237
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
238
              <GridBagConstraints gridX="2" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
239
            </Constraint>
240
          </Constraints>
241
        </Component>
242
        <Component class="javax.swing.JLabel" name="staticFieldLabel">
243
          <Properties>
244
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
245
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_StaticField" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
246
            </Property>
247
          </Properties>
248
          <Constraints>
249
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
250
              <GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
251
            </Constraint>
252
          </Constraints>
253
        </Component>
254
        <Component class="javax.swing.JTextField" name="staticFieldPrefixField">
255
          <Properties>
256
            <Property name="columns" type="int" value="5"/>
257
          </Properties>
258
          <Constraints>
259
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
260
              <GridBagConstraints gridX="1" gridY="2" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
261
            </Constraint>
262
          </Constraints>
263
        </Component>
264
        <Component class="javax.swing.JTextField" name="staticFieldSuffixField">
265
          <Properties>
266
            <Property name="columns" type="int" value="5"/>
267
          </Properties>
268
          <Constraints>
269
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
270
              <GridBagConstraints gridX="2" gridY="2" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
271
            </Constraint>
272
          </Constraints>
273
        </Component>
274
        <Component class="javax.swing.JLabel" name="parameterLabel">
275
          <Properties>
276
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
277
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_Parameter" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
278
            </Property>
279
          </Properties>
280
          <Constraints>
281
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
282
              <GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
283
            </Constraint>
284
          </Constraints>
285
        </Component>
286
        <Component class="javax.swing.JTextField" name="parameterPrefixField">
287
          <Properties>
288
            <Property name="columns" type="int" value="5"/>
289
          </Properties>
290
          <Constraints>
291
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
292
              <GridBagConstraints gridX="1" gridY="3" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
293
            </Constraint>
294
          </Constraints>
295
        </Component>
296
        <Component class="javax.swing.JTextField" name="parameterSuffixField">
297
          <Properties>
298
            <Property name="columns" type="int" value="5"/>
299
          </Properties>
300
          <Constraints>
301
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
302
              <GridBagConstraints gridX="2" gridY="3" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
303
            </Constraint>
304
          </Constraints>
305
        </Component>
306
        <Component class="javax.swing.JLabel" name="localVarLabel">
307
          <Properties>
308
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
309
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_LocalVariable" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
310
            </Property>
311
          </Properties>
312
          <Constraints>
313
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
314
              <GridBagConstraints gridX="0" gridY="4" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
315
            </Constraint>
316
          </Constraints>
317
        </Component>
318
        <Component class="javax.swing.JTextField" name="localVarSuffixField">
319
          <Properties>
320
            <Property name="columns" type="int" value="5"/>
321
          </Properties>
322
          <Constraints>
323
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
324
              <GridBagConstraints gridX="1" gridY="4" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
325
            </Constraint>
326
          </Constraints>
327
        </Component>
328
        <Component class="javax.swing.JTextField" name="localVarPrefixField">
329
          <Properties>
330
            <Property name="columns" type="int" value="5"/>
331
          </Properties>
332
          <Constraints>
333
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
334
              <GridBagConstraints gridX="2" gridY="4" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
335
            </Constraint>
336
          </Constraints>
337
        </Component>
338
      </SubComponents>
339
    </Container>
340
    <Component class="javax.swing.JSeparator" name="jSeparator1">
341
    </Component>
342
    <Component class="javax.swing.JLabel" name="otherLabel">
125
    <Component class="javax.swing.JLabel" name="otherLabel">
343
      <Properties>
126
      <Properties>
344
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
127
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
(-)a/java.source/src/org/netbeans/modules/java/ui/FmtCodeGeneration.java (-230 / +13 lines)
Lines 106-121 Link Here
106
    public FmtCodeGeneration() {
106
    public FmtCodeGeneration() {
107
        initComponents();
107
        initComponents();
108
        
108
        
109
        preferLongerNamesCheckBox.putClientProperty(OPTION_ID, preferLongerNames);
110
        isForBooleanGettersCheckBox.putClientProperty(OPTION_ID, useIsForBooleanGetters);
111
        fieldPrefixField.putClientProperty(OPTION_ID, fieldNamePrefix);
112
        fieldSuffixField.putClientProperty(OPTION_ID, fieldNameSuffix);
113
        staticFieldPrefixField.putClientProperty(OPTION_ID, staticFieldNamePrefix);
114
        staticFieldSuffixField.putClientProperty(OPTION_ID, staticFieldNameSuffix);
115
        parameterPrefixField.putClientProperty(OPTION_ID, parameterNamePrefix);
116
        parameterSuffixField.putClientProperty(OPTION_ID, parameterNameSuffix);
117
        localVarPrefixField.putClientProperty(OPTION_ID, localVarNamePrefix);
118
        localVarSuffixField.putClientProperty(OPTION_ID, localVarNameSuffix);
119
        qualifyFieldAccessCheckBox.putClientProperty(OPTION_ID, qualifyFieldAccess);
109
        qualifyFieldAccessCheckBox.putClientProperty(OPTION_ID, qualifyFieldAccess);
120
        addOverrideAnnortationCheckBox.putClientProperty(OPTION_ID, addOverrideAnnotation);
110
        addOverrideAnnortationCheckBox.putClientProperty(OPTION_ID, addOverrideAnnotation);
121
        parametersFinalCheckBox.putClientProperty(OPTION_ID, makeParametersFinal);
111
        parametersFinalCheckBox.putClientProperty(OPTION_ID, makeParametersFinal);
Lines 144-167 Link Here
144
        visibilityOrderList.setSelectedIndex(0);
134
        visibilityOrderList.setSelectedIndex(0);
145
        visibilityOrderList.addListSelectionListener(this);
135
        visibilityOrderList.addListSelectionListener(this);
146
        enableVisibilityOrder();
136
        enableVisibilityOrder();
147
        namingConventionsLabel.setVisible(false);
148
        preferLongerNamesCheckBox.setVisible(false);
149
        isForBooleanGettersCheckBox.setVisible(false);
150
        prefixLabel.setVisible(false);
151
        suffixLabel.setVisible(false);
152
        fieldLabel.setVisible(false);
153
        fieldPrefixField.setVisible(false);
154
        fieldSuffixField.setVisible(false);
155
        staticFieldLabel.setVisible(false);
156
        staticFieldPrefixField.setVisible(false);
157
        staticFieldSuffixField.setVisible(false);
158
        parameterLabel.setVisible(false);
159
        parameterPrefixField.setVisible(false);
160
        parameterSuffixField.setVisible(false);
161
        localVarLabel.setVisible(false);
162
        localVarPrefixField.setVisible(false);
163
        localVarSuffixField.setVisible(false);
164
        jSeparator1.setVisible(false);
165
        otherLabel.setVisible(false);
137
        otherLabel.setVisible(false);
166
        qualifyFieldAccessCheckBox.setVisible(false);
138
        qualifyFieldAccessCheckBox.setVisible(false);
167
        addOverrideAnnortationCheckBox.setVisible(false);
139
        addOverrideAnnortationCheckBox.setVisible(false);
Lines 187-211 Link Here
187
    private void initComponents() {
159
    private void initComponents() {
188
        java.awt.GridBagConstraints gridBagConstraints;
160
        java.awt.GridBagConstraints gridBagConstraints;
189
161
190
        namingConventionsLabel = new javax.swing.JLabel();
191
        preferLongerNamesCheckBox = new javax.swing.JCheckBox();
192
        isForBooleanGettersCheckBox = new javax.swing.JCheckBox();
193
        jPanel1 = new javax.swing.JPanel();
194
        prefixLabel = new javax.swing.JLabel();
195
        suffixLabel = new javax.swing.JLabel();
196
        fieldLabel = new javax.swing.JLabel();
197
        fieldPrefixField = new javax.swing.JTextField();
198
        fieldSuffixField = new javax.swing.JTextField();
199
        staticFieldLabel = new javax.swing.JLabel();
200
        staticFieldPrefixField = new javax.swing.JTextField();
201
        staticFieldSuffixField = new javax.swing.JTextField();
202
        parameterLabel = new javax.swing.JLabel();
203
        parameterPrefixField = new javax.swing.JTextField();
204
        parameterSuffixField = new javax.swing.JTextField();
205
        localVarLabel = new javax.swing.JLabel();
206
        localVarSuffixField = new javax.swing.JTextField();
207
        localVarPrefixField = new javax.swing.JTextField();
208
        jSeparator1 = new javax.swing.JSeparator();
209
        otherLabel = new javax.swing.JLabel();
162
        otherLabel = new javax.swing.JLabel();
210
        qualifyFieldAccessCheckBox = new javax.swing.JCheckBox();
163
        qualifyFieldAccessCheckBox = new javax.swing.JCheckBox();
211
        addOverrideAnnortationCheckBox = new javax.swing.JCheckBox();
164
        addOverrideAnnortationCheckBox = new javax.swing.JCheckBox();
Lines 229-369 Link Here
229
        setName(org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_CodeGeneration")); // NOI18N
182
        setName(org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_CodeGeneration")); // NOI18N
230
        setOpaque(false);
183
        setOpaque(false);
231
184
232
        org.openide.awt.Mnemonics.setLocalizedText(namingConventionsLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Naming")); // NOI18N
233
234
        org.openide.awt.Mnemonics.setLocalizedText(preferLongerNamesCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_PreferLongerNames")); // NOI18N
235
        preferLongerNamesCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
236
        preferLongerNamesCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
237
        preferLongerNamesCheckBox.setOpaque(false);
238
239
        org.openide.awt.Mnemonics.setLocalizedText(isForBooleanGettersCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_UseIsForBooleanGetters")); // NOI18N
240
        isForBooleanGettersCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
241
        isForBooleanGettersCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
242
        isForBooleanGettersCheckBox.setOpaque(false);
243
244
        jPanel1.setLayout(new java.awt.GridBagLayout());
245
246
        org.openide.awt.Mnemonics.setLocalizedText(prefixLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Prefix")); // NOI18N
247
        gridBagConstraints = new java.awt.GridBagConstraints();
248
        gridBagConstraints.gridx = 1;
249
        gridBagConstraints.gridy = 0;
250
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
251
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
252
        gridBagConstraints.weightx = 0.5;
253
        gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0);
254
        jPanel1.add(prefixLabel, gridBagConstraints);
255
256
        org.openide.awt.Mnemonics.setLocalizedText(suffixLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Suffix")); // NOI18N
257
        gridBagConstraints = new java.awt.GridBagConstraints();
258
        gridBagConstraints.gridx = 2;
259
        gridBagConstraints.gridy = 0;
260
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
261
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
262
        gridBagConstraints.weightx = 0.5;
263
        gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0);
264
        jPanel1.add(suffixLabel, gridBagConstraints);
265
266
        org.openide.awt.Mnemonics.setLocalizedText(fieldLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Field")); // NOI18N
267
        gridBagConstraints = new java.awt.GridBagConstraints();
268
        gridBagConstraints.gridx = 0;
269
        gridBagConstraints.gridy = 1;
270
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
271
        jPanel1.add(fieldLabel, gridBagConstraints);
272
273
        fieldPrefixField.setColumns(5);
274
        gridBagConstraints = new java.awt.GridBagConstraints();
275
        gridBagConstraints.gridx = 1;
276
        gridBagConstraints.gridy = 1;
277
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
278
        gridBagConstraints.weightx = 0.5;
279
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
280
        jPanel1.add(fieldPrefixField, gridBagConstraints);
281
282
        fieldSuffixField.setColumns(5);
283
        gridBagConstraints = new java.awt.GridBagConstraints();
284
        gridBagConstraints.gridx = 2;
285
        gridBagConstraints.gridy = 1;
286
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
287
        gridBagConstraints.weightx = 0.5;
288
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
289
        jPanel1.add(fieldSuffixField, gridBagConstraints);
290
291
        org.openide.awt.Mnemonics.setLocalizedText(staticFieldLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_StaticField")); // NOI18N
292
        gridBagConstraints = new java.awt.GridBagConstraints();
293
        gridBagConstraints.gridx = 0;
294
        gridBagConstraints.gridy = 2;
295
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
296
        jPanel1.add(staticFieldLabel, gridBagConstraints);
297
298
        staticFieldPrefixField.setColumns(5);
299
        gridBagConstraints = new java.awt.GridBagConstraints();
300
        gridBagConstraints.gridx = 1;
301
        gridBagConstraints.gridy = 2;
302
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
303
        gridBagConstraints.weightx = 0.5;
304
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
305
        jPanel1.add(staticFieldPrefixField, gridBagConstraints);
306
307
        staticFieldSuffixField.setColumns(5);
308
        gridBagConstraints = new java.awt.GridBagConstraints();
309
        gridBagConstraints.gridx = 2;
310
        gridBagConstraints.gridy = 2;
311
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
312
        gridBagConstraints.weightx = 0.5;
313
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
314
        jPanel1.add(staticFieldSuffixField, gridBagConstraints);
315
316
        org.openide.awt.Mnemonics.setLocalizedText(parameterLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Parameter")); // NOI18N
317
        gridBagConstraints = new java.awt.GridBagConstraints();
318
        gridBagConstraints.gridx = 0;
319
        gridBagConstraints.gridy = 3;
320
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
321
        jPanel1.add(parameterLabel, gridBagConstraints);
322
323
        parameterPrefixField.setColumns(5);
324
        gridBagConstraints = new java.awt.GridBagConstraints();
325
        gridBagConstraints.gridx = 1;
326
        gridBagConstraints.gridy = 3;
327
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
328
        gridBagConstraints.weightx = 0.5;
329
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
330
        jPanel1.add(parameterPrefixField, gridBagConstraints);
331
332
        parameterSuffixField.setColumns(5);
333
        gridBagConstraints = new java.awt.GridBagConstraints();
334
        gridBagConstraints.gridx = 2;
335
        gridBagConstraints.gridy = 3;
336
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
337
        gridBagConstraints.weightx = 0.5;
338
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
339
        jPanel1.add(parameterSuffixField, gridBagConstraints);
340
341
        org.openide.awt.Mnemonics.setLocalizedText(localVarLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_LocalVariable")); // NOI18N
342
        gridBagConstraints = new java.awt.GridBagConstraints();
343
        gridBagConstraints.gridx = 0;
344
        gridBagConstraints.gridy = 4;
345
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
346
        gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
347
        jPanel1.add(localVarLabel, gridBagConstraints);
348
349
        localVarSuffixField.setColumns(5);
350
        gridBagConstraints = new java.awt.GridBagConstraints();
351
        gridBagConstraints.gridx = 1;
352
        gridBagConstraints.gridy = 4;
353
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
354
        gridBagConstraints.weightx = 0.5;
355
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 0, 0);
356
        jPanel1.add(localVarSuffixField, gridBagConstraints);
357
358
        localVarPrefixField.setColumns(5);
359
        gridBagConstraints = new java.awt.GridBagConstraints();
360
        gridBagConstraints.gridx = 2;
361
        gridBagConstraints.gridy = 4;
362
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
363
        gridBagConstraints.weightx = 0.5;
364
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 0, 0);
365
        jPanel1.add(localVarPrefixField, gridBagConstraints);
366
367
        org.openide.awt.Mnemonics.setLocalizedText(otherLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Other")); // NOI18N
185
        org.openide.awt.Mnemonics.setLocalizedText(otherLabel, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_Other")); // NOI18N
368
186
369
        org.openide.awt.Mnemonics.setLocalizedText(qualifyFieldAccessCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_QualifyFieldAccess")); // NOI18N
187
        org.openide.awt.Mnemonics.setLocalizedText(qualifyFieldAccessCheckBox, org.openide.util.NbBundle.getMessage(FmtCodeGeneration.class, "LBL_gen_QualifyFieldAccess")); // NOI18N
Lines 448-454 Link Here
448
        this.setLayout(layout);
266
        this.setLayout(layout);
449
        layout.setHorizontalGroup(
267
        layout.setHorizontalGroup(
450
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
268
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
451
            .addComponent(jSeparator1)
452
            .addGroup(layout.createSequentialGroup()
269
            .addGroup(layout.createSequentialGroup()
453
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
270
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
454
                    .addComponent(otherLabel)
271
                    .addComponent(otherLabel)
Lines 463-510 Link Here
463
            .addComponent(jSeparator3)
280
            .addComponent(jSeparator3)
464
            .addGroup(layout.createSequentialGroup()
281
            .addGroup(layout.createSequentialGroup()
465
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
282
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
466
                    .addComponent(namingConventionsLabel)
467
                    .addComponent(memberOrderLabel)
283
                    .addComponent(memberOrderLabel)
468
                    .addGroup(layout.createSequentialGroup()
284
                    .addGroup(layout.createSequentialGroup()
469
                        .addContainerGap()
285
                        .addContainerGap()
470
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
286
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
471
                            .addComponent(isForBooleanGettersCheckBox)
287
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
472
                            .addComponent(preferLongerNamesCheckBox)
288
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
473
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE)
289
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
474
                            .addGroup(layout.createSequentialGroup()
290
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
475
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
291
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
476
                                    .addComponent(jScrollPane1)
292
                                .addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
477
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
293
                                .addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
478
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
294
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
479
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
295
                                .addComponent(visDownButton, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
480
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
296
                                .addComponent(visUpButton, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))))
481
                                        .addComponent(downButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
482
                                        .addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
483
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
484
                                        .addComponent(visDownButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
485
                                        .addComponent(visUpButton, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))))))
486
                    .addComponent(sortByVisibilityCheckBox)
297
                    .addComponent(sortByVisibilityCheckBox)
487
                    .addGroup(layout.createSequentialGroup()
298
                    .addGroup(layout.createSequentialGroup()
488
                        .addGap(5, 5, 5)
299
                        .addGap(5, 5, 5)
489
                        .addComponent(insertionPointLabel)
300
                        .addComponent(insertionPointLabel)
490
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
301
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
491
                        .addComponent(insertionPointComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
302
                        .addComponent(insertionPointComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
492
                .addContainerGap())
303
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
493
            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING)
304
            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING)
494
        );
305
        );
495
        layout.setVerticalGroup(
306
        layout.setVerticalGroup(
496
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
307
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
497
            .addGroup(layout.createSequentialGroup()
308
            .addGroup(layout.createSequentialGroup()
498
                .addComponent(namingConventionsLabel)
309
                .addContainerGap()
499
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
500
                .addComponent(preferLongerNamesCheckBox)
501
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
502
                .addComponent(isForBooleanGettersCheckBox)
503
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
504
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
505
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
506
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
507
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
508
                .addComponent(otherLabel)
310
                .addComponent(otherLabel)
509
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
311
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
510
                .addComponent(qualifyFieldAccessCheckBox)
312
                .addComponent(qualifyFieldAccessCheckBox)
Lines 605-642 Link Here
605
    // Variables declaration - do not modify//GEN-BEGIN:variables
407
    // Variables declaration - do not modify//GEN-BEGIN:variables
606
    private javax.swing.JCheckBox addOverrideAnnortationCheckBox;
408
    private javax.swing.JCheckBox addOverrideAnnortationCheckBox;
607
    private javax.swing.JButton downButton;
409
    private javax.swing.JButton downButton;
608
    private javax.swing.JLabel fieldLabel;
609
    private javax.swing.JTextField fieldPrefixField;
610
    private javax.swing.JTextField fieldSuffixField;
611
    private javax.swing.JComboBox insertionPointComboBox;
410
    private javax.swing.JComboBox insertionPointComboBox;
612
    private javax.swing.JLabel insertionPointLabel;
411
    private javax.swing.JLabel insertionPointLabel;
613
    private javax.swing.JCheckBox isForBooleanGettersCheckBox;
614
    private javax.swing.JPanel jPanel1;
615
    private javax.swing.JScrollPane jScrollPane1;
412
    private javax.swing.JScrollPane jScrollPane1;
616
    private javax.swing.JScrollPane jScrollPane2;
413
    private javax.swing.JScrollPane jScrollPane2;
617
    private javax.swing.JSeparator jSeparator1;
618
    private javax.swing.JSeparator jSeparator2;
414
    private javax.swing.JSeparator jSeparator2;
619
    private javax.swing.JSeparator jSeparator3;
415
    private javax.swing.JSeparator jSeparator3;
620
    private javax.swing.JLabel localVarLabel;
621
    private javax.swing.JTextField localVarPrefixField;
622
    private javax.swing.JTextField localVarSuffixField;
623
    private javax.swing.JCheckBox localVarsFinalCheckBox;
416
    private javax.swing.JCheckBox localVarsFinalCheckBox;
624
    private javax.swing.JLabel memberOrderLabel;
417
    private javax.swing.JLabel memberOrderLabel;
625
    private javax.swing.JList membersOrderList;
418
    private javax.swing.JList membersOrderList;
626
    private javax.swing.JLabel namingConventionsLabel;
627
    private javax.swing.JLabel otherLabel;
419
    private javax.swing.JLabel otherLabel;
628
    private javax.swing.JLabel parameterLabel;
629
    private javax.swing.JTextField parameterPrefixField;
630
    private javax.swing.JTextField parameterSuffixField;
631
    private javax.swing.JCheckBox parametersFinalCheckBox;
420
    private javax.swing.JCheckBox parametersFinalCheckBox;
632
    private javax.swing.JCheckBox preferLongerNamesCheckBox;
633
    private javax.swing.JLabel prefixLabel;
634
    private javax.swing.JCheckBox qualifyFieldAccessCheckBox;
421
    private javax.swing.JCheckBox qualifyFieldAccessCheckBox;
635
    private javax.swing.JCheckBox sortByVisibilityCheckBox;
422
    private javax.swing.JCheckBox sortByVisibilityCheckBox;
636
    private javax.swing.JLabel staticFieldLabel;
637
    private javax.swing.JTextField staticFieldPrefixField;
638
    private javax.swing.JTextField staticFieldSuffixField;
639
    private javax.swing.JLabel suffixLabel;
640
    private javax.swing.JButton upButton;
423
    private javax.swing.JButton upButton;
641
    private javax.swing.JButton visDownButton;
424
    private javax.swing.JButton visDownButton;
642
    private javax.swing.JButton visUpButton;
425
    private javax.swing.JButton visUpButton;
(-)bdb0f6cd71ec (+255 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.8" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <Properties>
5
    <Property name="name" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
6
      <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_Naming" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
7
    </Property>
8
    <Property name="opaque" type="boolean" value="false"/>
9
  </Properties>
10
  <AuxValues>
11
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
12
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
13
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
14
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
15
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
16
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
17
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
18
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
19
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
20
  </AuxValues>
21
22
  <Layout>
23
    <DimensionLayout dim="0">
24
      <Group type="103" groupAlignment="0" attributes="0">
25
          <Group type="102" attributes="0">
26
              <Group type="103" groupAlignment="0" attributes="0">
27
                  <Component id="namingConventionsLabel" min="-2" max="-2" attributes="0"/>
28
                  <Group type="102" attributes="0">
29
                      <EmptySpace max="-2" attributes="0"/>
30
                      <Group type="103" groupAlignment="0" attributes="0">
31
                          <Component id="isForBooleanGettersCheckBox" min="-2" max="-2" attributes="0"/>
32
                          <Component id="preferLongerNamesCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
33
                          <Component id="jPanel1" alignment="0" min="-2" pref="274" max="-2" attributes="0"/>
34
                      </Group>
35
                  </Group>
36
              </Group>
37
              <EmptySpace max="32767" attributes="0"/>
38
          </Group>
39
      </Group>
40
    </DimensionLayout>
41
    <DimensionLayout dim="1">
42
      <Group type="103" groupAlignment="0" attributes="0">
43
          <Group type="102" attributes="0">
44
              <Component id="namingConventionsLabel" min="-2" max="-2" attributes="0"/>
45
              <EmptySpace max="-2" attributes="0"/>
46
              <Component id="preferLongerNamesCheckBox" min="-2" max="-2" attributes="0"/>
47
              <EmptySpace max="-2" attributes="0"/>
48
              <Component id="isForBooleanGettersCheckBox" min="-2" max="-2" attributes="0"/>
49
              <EmptySpace max="-2" attributes="0"/>
50
              <Component id="jPanel1" min="-2" max="-2" attributes="0"/>
51
              <EmptySpace max="32767" attributes="0"/>
52
          </Group>
53
      </Group>
54
    </DimensionLayout>
55
  </Layout>
56
  <SubComponents>
57
    <Component class="javax.swing.JLabel" name="namingConventionsLabel">
58
      <Properties>
59
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
60
          <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_Naming" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
61
        </Property>
62
      </Properties>
63
    </Component>
64
    <Component class="javax.swing.JCheckBox" name="preferLongerNamesCheckBox">
65
      <Properties>
66
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
67
          <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_PreferLongerNames" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
68
        </Property>
69
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
70
          <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
71
            <EmptyBorder bottom="0" left="0" right="0" top="0"/>
72
          </Border>
73
        </Property>
74
        <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
75
          <Insets value="[0, 0, 0, 0]"/>
76
        </Property>
77
        <Property name="opaque" type="boolean" value="false"/>
78
      </Properties>
79
    </Component>
80
    <Component class="javax.swing.JCheckBox" name="isForBooleanGettersCheckBox">
81
      <Properties>
82
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
83
          <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_UseIsForBooleanGetters" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
84
        </Property>
85
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
86
          <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
87
            <EmptyBorder bottom="0" left="0" right="0" top="0"/>
88
          </Border>
89
        </Property>
90
        <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
91
          <Insets value="[0, 0, 0, 0]"/>
92
        </Property>
93
        <Property name="opaque" type="boolean" value="false"/>
94
      </Properties>
95
    </Component>
96
    <Container class="javax.swing.JPanel" name="jPanel1">
97
98
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
99
      <SubComponents>
100
        <Component class="javax.swing.JLabel" name="prefixLabel">
101
          <Properties>
102
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
103
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_Prefix" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
104
            </Property>
105
          </Properties>
106
          <Constraints>
107
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
108
              <GridBagConstraints gridX="1" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="17" weightX="0.5" weightY="0.0"/>
109
            </Constraint>
110
          </Constraints>
111
        </Component>
112
        <Component class="javax.swing.JLabel" name="suffixLabel">
113
          <Properties>
114
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
115
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_Suffix" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
116
            </Property>
117
          </Properties>
118
          <Constraints>
119
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
120
              <GridBagConstraints gridX="2" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="17" weightX="0.5" weightY="0.0"/>
121
            </Constraint>
122
          </Constraints>
123
        </Component>
124
        <Component class="javax.swing.JLabel" name="fieldLabel">
125
          <Properties>
126
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
127
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_Field" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
128
            </Property>
129
          </Properties>
130
          <Constraints>
131
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
132
              <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
133
            </Constraint>
134
          </Constraints>
135
        </Component>
136
        <Component class="javax.swing.JTextField" name="fieldPrefixField">
137
          <Properties>
138
            <Property name="columns" type="int" value="5"/>
139
          </Properties>
140
          <Constraints>
141
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
142
              <GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
143
            </Constraint>
144
          </Constraints>
145
        </Component>
146
        <Component class="javax.swing.JTextField" name="fieldSuffixField">
147
          <Properties>
148
            <Property name="columns" type="int" value="5"/>
149
          </Properties>
150
          <Constraints>
151
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
152
              <GridBagConstraints gridX="2" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
153
            </Constraint>
154
          </Constraints>
155
        </Component>
156
        <Component class="javax.swing.JLabel" name="staticFieldLabel">
157
          <Properties>
158
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
159
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_StaticField" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
160
            </Property>
161
          </Properties>
162
          <Constraints>
163
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
164
              <GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
165
            </Constraint>
166
          </Constraints>
167
        </Component>
168
        <Component class="javax.swing.JTextField" name="staticFieldPrefixField">
169
          <Properties>
170
            <Property name="columns" type="int" value="5"/>
171
          </Properties>
172
          <Constraints>
173
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
174
              <GridBagConstraints gridX="1" gridY="2" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
175
            </Constraint>
176
          </Constraints>
177
        </Component>
178
        <Component class="javax.swing.JTextField" name="staticFieldSuffixField">
179
          <Properties>
180
            <Property name="columns" type="int" value="5"/>
181
          </Properties>
182
          <Constraints>
183
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
184
              <GridBagConstraints gridX="2" gridY="2" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
185
            </Constraint>
186
          </Constraints>
187
        </Component>
188
        <Component class="javax.swing.JLabel" name="parameterLabel">
189
          <Properties>
190
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
191
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_Parameter" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
192
            </Property>
193
          </Properties>
194
          <Constraints>
195
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
196
              <GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
197
            </Constraint>
198
          </Constraints>
199
        </Component>
200
        <Component class="javax.swing.JTextField" name="parameterPrefixField">
201
          <Properties>
202
            <Property name="columns" type="int" value="5"/>
203
          </Properties>
204
          <Constraints>
205
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
206
              <GridBagConstraints gridX="1" gridY="3" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
207
            </Constraint>
208
          </Constraints>
209
        </Component>
210
        <Component class="javax.swing.JTextField" name="parameterSuffixField">
211
          <Properties>
212
            <Property name="columns" type="int" value="5"/>
213
          </Properties>
214
          <Constraints>
215
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
216
              <GridBagConstraints gridX="2" gridY="3" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="4" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
217
            </Constraint>
218
          </Constraints>
219
        </Component>
220
        <Component class="javax.swing.JLabel" name="localVarLabel">
221
          <Properties>
222
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
223
              <ResourceString bundle="org/netbeans/modules/java/ui/Bundle.properties" key="LBL_gen_LocalVariable" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
224
            </Property>
225
          </Properties>
226
          <Constraints>
227
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
228
              <GridBagConstraints gridX="0" gridY="4" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
229
            </Constraint>
230
          </Constraints>
231
        </Component>
232
        <Component class="javax.swing.JTextField" name="localVarSuffixField">
233
          <Properties>
234
            <Property name="columns" type="int" value="5"/>
235
          </Properties>
236
          <Constraints>
237
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
238
              <GridBagConstraints gridX="2" gridY="4" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
239
            </Constraint>
240
          </Constraints>
241
        </Component>
242
        <Component class="javax.swing.JTextField" name="localVarPrefixField">
243
          <Properties>
244
            <Property name="columns" type="int" value="5"/>
245
          </Properties>
246
          <Constraints>
247
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
248
              <GridBagConstraints gridX="1" gridY="4" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
249
            </Constraint>
250
          </Constraints>
251
        </Component>
252
      </SubComponents>
253
    </Container>
254
  </SubComponents>
255
</Form>
(-)bdb0f6cd71ec (+478 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
package org.netbeans.modules.java.ui;
45
46
import java.awt.Rectangle;
47
import java.util.ArrayList;
48
import java.util.Collections;
49
import java.util.EnumSet;
50
import java.util.List;
51
import java.util.prefs.Preferences;
52
53
import javax.lang.model.element.ElementKind;
54
import javax.lang.model.element.Modifier;
55
import javax.swing.DefaultListModel;
56
import javax.swing.JEditorPane;
57
import javax.swing.JList;
58
import javax.swing.JPanel;
59
import javax.swing.text.BadLocationException;
60
import javax.swing.text.Document;
61
62
import com.sun.source.tree.AssignmentTree;
63
import com.sun.source.tree.BlockTree;
64
import com.sun.source.tree.ClassTree;
65
import com.sun.source.tree.CompilationUnitTree;
66
import com.sun.source.tree.ExpressionTree;
67
import com.sun.source.tree.IdentifierTree;
68
import com.sun.source.tree.ModifiersTree;
69
import com.sun.source.tree.NewClassTree;
70
import com.sun.source.tree.Tree;
71
import com.sun.source.tree.TypeParameterTree;
72
import com.sun.source.tree.VariableTree;
73
import javax.lang.model.type.TypeKind;
74
import javax.swing.event.DocumentEvent;
75
import javax.swing.event.DocumentListener;
76
77
import org.netbeans.api.java.source.CodeStyle;
78
import org.netbeans.api.java.source.CodeStyleUtils;
79
import org.netbeans.api.java.source.GeneratorUtilities;
80
import org.netbeans.api.java.source.JavaSource.Phase;
81
import org.netbeans.api.java.source.ModificationResult;
82
import org.netbeans.api.java.source.TreeMaker;
83
import org.netbeans.api.java.source.WorkingCopy;
84
import org.netbeans.editor.BaseDocument;
85
import org.netbeans.modules.editor.indent.api.Reformat;
86
import static org.netbeans.modules.java.ui.FmtOptions.*;
87
import org.netbeans.modules.java.ui.FmtOptions.CategorySupport;
88
import static org.netbeans.modules.java.ui.FmtOptions.CategorySupport.OPTION_ID;
89
import org.netbeans.modules.options.editor.spi.PreferencesCustomizer;
90
import org.netbeans.modules.parsing.api.ResultIterator;
91
import org.netbeans.modules.parsing.api.Source;
92
import org.netbeans.modules.parsing.api.UserTask;
93
import org.openide.cookies.SaveCookie;
94
import org.openide.filesystems.FileObject;
95
import org.openide.filesystems.FileUtil;
96
import org.openide.loaders.DataObject;
97
import org.openide.util.NbBundle;
98
99
/**
100
 *
101
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
102
 */
103
public class FmtNaming extends javax.swing.JPanel implements Runnable {
104
105
    /**
106
     * Creates new form FmtCodeGeneration
107
     */
108
    public FmtNaming() {
109
        initComponents();
110
        preferLongerNamesCheckBox.putClientProperty(OPTION_ID, preferLongerNames);
111
        isForBooleanGettersCheckBox.putClientProperty(OPTION_ID, useIsForBooleanGetters);
112
        fieldPrefixField.putClientProperty(OPTION_ID, fieldNamePrefix);
113
        fieldSuffixField.putClientProperty(OPTION_ID, fieldNameSuffix);
114
        staticFieldPrefixField.putClientProperty(OPTION_ID, staticFieldNamePrefix);
115
        staticFieldSuffixField.putClientProperty(OPTION_ID, staticFieldNameSuffix);
116
        parameterPrefixField.putClientProperty(OPTION_ID, parameterNamePrefix);
117
        parameterSuffixField.putClientProperty(OPTION_ID, parameterNameSuffix);
118
        localVarPrefixField.putClientProperty(OPTION_ID, localVarNamePrefix);
119
        localVarSuffixField.putClientProperty(OPTION_ID, localVarNameSuffix);
120
    }
121
122
    public static PreferencesCustomizer.Factory getController() {
123
        return new PreferencesCustomizer.Factory() {
124
            public PreferencesCustomizer create(Preferences preferences) {
125
                NamingCategorySupport support = new NamingCategorySupport(preferences, new FmtNaming());
126
                ((Runnable) support.panel).run();
127
                return support;
128
            }
129
        };
130
    }
131
132
    /**
133
     * This method is called from within the constructor to initialize the form.
134
     * WARNING: Do NOT modify this code. The content of this method is always
135
     * regenerated by the Form Editor.
136
     */
137
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
138
    private void initComponents() {
139
        java.awt.GridBagConstraints gridBagConstraints;
140
141
        namingConventionsLabel = new javax.swing.JLabel();
142
        preferLongerNamesCheckBox = new javax.swing.JCheckBox();
143
        isForBooleanGettersCheckBox = new javax.swing.JCheckBox();
144
        jPanel1 = new javax.swing.JPanel();
145
        prefixLabel = new javax.swing.JLabel();
146
        suffixLabel = new javax.swing.JLabel();
147
        fieldLabel = new javax.swing.JLabel();
148
        fieldPrefixField = new javax.swing.JTextField();
149
        fieldSuffixField = new javax.swing.JTextField();
150
        staticFieldLabel = new javax.swing.JLabel();
151
        staticFieldPrefixField = new javax.swing.JTextField();
152
        staticFieldSuffixField = new javax.swing.JTextField();
153
        parameterLabel = new javax.swing.JLabel();
154
        parameterPrefixField = new javax.swing.JTextField();
155
        parameterSuffixField = new javax.swing.JTextField();
156
        localVarLabel = new javax.swing.JLabel();
157
        localVarSuffixField = new javax.swing.JTextField();
158
        localVarPrefixField = new javax.swing.JTextField();
159
160
        setName(org.openide.util.NbBundle.getMessage(FmtNaming.class, "LBL_Naming")); // NOI18N
161
        setOpaque(false);
162
163
        org.openide.awt.Mnemonics.setLocalizedText(namingConventionsLabel, org.openide.util.NbBundle.getMessage(FmtNaming.class, "LBL_gen_Naming")); // NOI18N
164
165
        org.openide.awt.Mnemonics.setLocalizedText(preferLongerNamesCheckBox, org.openide.util.NbBundle.getMessage(FmtNaming.class, "LBL_gen_PreferLongerNames")); // NOI18N
166
        preferLongerNamesCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
167
        preferLongerNamesCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
168
        preferLongerNamesCheckBox.setOpaque(false);
169
170
        org.openide.awt.Mnemonics.setLocalizedText(isForBooleanGettersCheckBox, org.openide.util.NbBundle.getMessage(FmtNaming.class, "LBL_gen_UseIsForBooleanGetters")); // NOI18N
171
        isForBooleanGettersCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
172
        isForBooleanGettersCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
173
        isForBooleanGettersCheckBox.setOpaque(false);
174
175
        jPanel1.setLayout(new java.awt.GridBagLayout());
176
177
        org.openide.awt.Mnemonics.setLocalizedText(prefixLabel, org.openide.util.NbBundle.getMessage(FmtNaming.class, "LBL_gen_Prefix")); // NOI18N
178
        gridBagConstraints = new java.awt.GridBagConstraints();
179
        gridBagConstraints.gridx = 1;
180
        gridBagConstraints.gridy = 0;
181
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
182
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
183
        gridBagConstraints.weightx = 0.5;
184
        gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0);
185
        jPanel1.add(prefixLabel, gridBagConstraints);
186
187
        org.openide.awt.Mnemonics.setLocalizedText(suffixLabel, org.openide.util.NbBundle.getMessage(FmtNaming.class, "LBL_gen_Suffix")); // NOI18N
188
        gridBagConstraints = new java.awt.GridBagConstraints();
189
        gridBagConstraints.gridx = 2;
190
        gridBagConstraints.gridy = 0;
191
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
192
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
193
        gridBagConstraints.weightx = 0.5;
194
        gridBagConstraints.insets = new java.awt.Insets(0, 8, 4, 0);
195
        jPanel1.add(suffixLabel, gridBagConstraints);
196
197
        org.openide.awt.Mnemonics.setLocalizedText(fieldLabel, org.openide.util.NbBundle.getMessage(FmtNaming.class, "LBL_gen_Field")); // NOI18N
198
        gridBagConstraints = new java.awt.GridBagConstraints();
199
        gridBagConstraints.gridx = 0;
200
        gridBagConstraints.gridy = 1;
201
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
202
        jPanel1.add(fieldLabel, gridBagConstraints);
203
204
        fieldPrefixField.setColumns(5);
205
        gridBagConstraints = new java.awt.GridBagConstraints();
206
        gridBagConstraints.gridx = 1;
207
        gridBagConstraints.gridy = 1;
208
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
209
        gridBagConstraints.weightx = 0.5;
210
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
211
        jPanel1.add(fieldPrefixField, gridBagConstraints);
212
213
        fieldSuffixField.setColumns(5);
214
        gridBagConstraints = new java.awt.GridBagConstraints();
215
        gridBagConstraints.gridx = 2;
216
        gridBagConstraints.gridy = 1;
217
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
218
        gridBagConstraints.weightx = 0.5;
219
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
220
        jPanel1.add(fieldSuffixField, gridBagConstraints);
221
222
        org.openide.awt.Mnemonics.setLocalizedText(staticFieldLabel, org.openide.util.NbBundle.getMessage(FmtNaming.class, "LBL_gen_StaticField")); // NOI18N
223
        gridBagConstraints = new java.awt.GridBagConstraints();
224
        gridBagConstraints.gridx = 0;
225
        gridBagConstraints.gridy = 2;
226
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
227
        jPanel1.add(staticFieldLabel, gridBagConstraints);
228
229
        staticFieldPrefixField.setColumns(5);
230
        gridBagConstraints = new java.awt.GridBagConstraints();
231
        gridBagConstraints.gridx = 1;
232
        gridBagConstraints.gridy = 2;
233
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
234
        gridBagConstraints.weightx = 0.5;
235
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
236
        jPanel1.add(staticFieldPrefixField, gridBagConstraints);
237
238
        staticFieldSuffixField.setColumns(5);
239
        gridBagConstraints = new java.awt.GridBagConstraints();
240
        gridBagConstraints.gridx = 2;
241
        gridBagConstraints.gridy = 2;
242
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
243
        gridBagConstraints.weightx = 0.5;
244
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
245
        jPanel1.add(staticFieldSuffixField, gridBagConstraints);
246
247
        org.openide.awt.Mnemonics.setLocalizedText(parameterLabel, org.openide.util.NbBundle.getMessage(FmtNaming.class, "LBL_gen_Parameter")); // NOI18N
248
        gridBagConstraints = new java.awt.GridBagConstraints();
249
        gridBagConstraints.gridx = 0;
250
        gridBagConstraints.gridy = 3;
251
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
252
        jPanel1.add(parameterLabel, gridBagConstraints);
253
254
        parameterPrefixField.setColumns(5);
255
        gridBagConstraints = new java.awt.GridBagConstraints();
256
        gridBagConstraints.gridx = 1;
257
        gridBagConstraints.gridy = 3;
258
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
259
        gridBagConstraints.weightx = 0.5;
260
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
261
        jPanel1.add(parameterPrefixField, gridBagConstraints);
262
263
        parameterSuffixField.setColumns(5);
264
        gridBagConstraints = new java.awt.GridBagConstraints();
265
        gridBagConstraints.gridx = 2;
266
        gridBagConstraints.gridy = 3;
267
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
268
        gridBagConstraints.weightx = 0.5;
269
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 0);
270
        jPanel1.add(parameterSuffixField, gridBagConstraints);
271
272
        org.openide.awt.Mnemonics.setLocalizedText(localVarLabel, org.openide.util.NbBundle.getMessage(FmtNaming.class, "LBL_gen_LocalVariable")); // NOI18N
273
        gridBagConstraints = new java.awt.GridBagConstraints();
274
        gridBagConstraints.gridx = 0;
275
        gridBagConstraints.gridy = 4;
276
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
277
        gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
278
        jPanel1.add(localVarLabel, gridBagConstraints);
279
280
        localVarSuffixField.setColumns(5);
281
        gridBagConstraints = new java.awt.GridBagConstraints();
282
        gridBagConstraints.gridx = 2;
283
        gridBagConstraints.gridy = 4;
284
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
285
        gridBagConstraints.weightx = 0.5;
286
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 0, 0);
287
        jPanel1.add(localVarSuffixField, gridBagConstraints);
288
289
        localVarPrefixField.setColumns(5);
290
        gridBagConstraints = new java.awt.GridBagConstraints();
291
        gridBagConstraints.gridx = 1;
292
        gridBagConstraints.gridy = 4;
293
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
294
        gridBagConstraints.weightx = 0.5;
295
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 0, 0);
296
        jPanel1.add(localVarPrefixField, gridBagConstraints);
297
298
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
299
        this.setLayout(layout);
300
        layout.setHorizontalGroup(
301
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302
            .addGroup(layout.createSequentialGroup()
303
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
304
                    .addComponent(namingConventionsLabel)
305
                    .addGroup(layout.createSequentialGroup()
306
                        .addContainerGap()
307
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308
                            .addComponent(isForBooleanGettersCheckBox)
309
                            .addComponent(preferLongerNamesCheckBox)
310
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE))))
311
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
312
        );
313
        layout.setVerticalGroup(
314
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
315
            .addGroup(layout.createSequentialGroup()
316
                .addComponent(namingConventionsLabel)
317
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
318
                .addComponent(preferLongerNamesCheckBox)
319
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
320
                .addComponent(isForBooleanGettersCheckBox)
321
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
322
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
323
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
324
        );
325
    }// </editor-fold>//GEN-END:initComponents
326
    // Variables declaration - do not modify//GEN-BEGIN:variables
327
    private javax.swing.JLabel fieldLabel;
328
    private javax.swing.JTextField fieldPrefixField;
329
    private javax.swing.JTextField fieldSuffixField;
330
    private javax.swing.JCheckBox isForBooleanGettersCheckBox;
331
    private javax.swing.JPanel jPanel1;
332
    private javax.swing.JLabel localVarLabel;
333
    private javax.swing.JTextField localVarPrefixField;
334
    private javax.swing.JTextField localVarSuffixField;
335
    private javax.swing.JLabel namingConventionsLabel;
336
    private javax.swing.JLabel parameterLabel;
337
    private javax.swing.JTextField parameterPrefixField;
338
    private javax.swing.JTextField parameterSuffixField;
339
    private javax.swing.JCheckBox preferLongerNamesCheckBox;
340
    private javax.swing.JLabel prefixLabel;
341
    private javax.swing.JLabel staticFieldLabel;
342
    private javax.swing.JTextField staticFieldPrefixField;
343
    private javax.swing.JTextField staticFieldSuffixField;
344
    private javax.swing.JLabel suffixLabel;
345
    // End of variables declaration//GEN-END:variables
346
347
    @Override
348
    public void run() {
349
        
350
    }
351
352
    private static final class NamingCategorySupport extends CategorySupport {
353
354
        private Source source = null;
355
356
        private NamingCategorySupport(Preferences preferences, JPanel panel) {
357
            super(preferences, "naming", panel, NbBundle.getMessage(FmtNaming.class, "SAMPLE_Naming"), //NOI18N
358
                  new String[]{FmtOptions.blankLinesBeforeFields, "1"}); //NOI18N
359
        }
360
361
        @Override
362
        public void refreshPreview() {
363
            final JEditorPane jep = (JEditorPane) getPreviewComponent();
364
            try {
365
                Class.forName(CodeStyle.class.getName(), true, CodeStyle.class.getClassLoader());
366
            } catch (ClassNotFoundException cnfe) {
367
                // ignore
368
            }
369
370
            final CodeStyle codeStyle = codeStyleProducer.create(previewPrefs);
371
            jep.setIgnoreRepaint(true);
372
            try {
373
                if (source == null) {
374
                    FileObject fo = FileUtil.createMemoryFileSystem().getRoot().createData("org.netbeans.samples.ClassA", "java"); //NOI18N
375
                    source = Source.create(fo);
376
                }
377
                final Document doc = source.getDocument(true);
378
                if (doc.getLength() > 0) {
379
                    doc.remove(0, doc.getLength());
380
                }
381
                doc.insertString(0, previewText, null);
382
                doc.putProperty(CodeStyle.class, codeStyle);
383
                jep.setDocument(doc);
384
                ModificationResult result = ModificationResult.runModificationTask(Collections.singleton(source), new UserTask() {
385
                    @Override
386
                    public void run(ResultIterator resultIterator) throws Exception {
387
                        WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult());
388
                        copy.toPhase(Phase.RESOLVED);
389
                        TreeMaker tm = copy.getTreeMaker();
390
                        GeneratorUtilities gu = GeneratorUtilities.get(copy);
391
                        CompilationUnitTree cut = copy.getCompilationUnit();
392
                        ClassTree ct = (ClassTree) cut.getTypeDecls().get(0);
393
                        List<Tree> members = new ArrayList<Tree>();
394
                        String name = CodeStyleUtils.addPrefixSuffix("name",
395
                                codeStyle.getFieldNamePrefix(),
396
                                codeStyle.getFieldNameSuffix());
397
                        VariableTree field = tm.Variable(tm.Modifiers(Collections.singleton(Modifier.PRIVATE)), name, tm.Type("String"), null);
398
                        members.add(field);
399
                        String cond = CodeStyleUtils.addPrefixSuffix("cond",
400
                                codeStyle.getFieldNamePrefix(),
401
                                codeStyle.getFieldNameSuffix());
402
                        VariableTree booleanField = tm.Variable(tm.Modifiers(Collections.singleton(Modifier.PRIVATE)), cond, tm.PrimitiveType(TypeKind.BOOLEAN), null);
403
                        members.add(booleanField);
404
                        members.add(gu.createConstructor(ct, Collections.singletonList(field)));
405
                        members.add(gu.createGetter(field));
406
                        members.add(gu.createSetter(ct, field));
407
                        members.add(gu.createGetter(booleanField));
408
                        members.add(gu.createSetter(ct, booleanField));
409
                        ModifiersTree mods = tm.Modifiers(EnumSet.of(Modifier.PRIVATE, Modifier.STATIC));
410
                        ClassTree nested = tm.Class(mods, "Nested", Collections.<TypeParameterTree>emptyList(), null, Collections.<Tree>emptyList(), Collections.<Tree>emptyList()); //NOI18N
411
                        members.add(nested);
412
                        IdentifierTree nestedId = tm.Identifier("Nested"); //NOI18N
413
                        String instance = CodeStyleUtils.addPrefixSuffix("instance",
414
                                codeStyle.getStaticFieldNamePrefix(),
415
                                codeStyle.getStaticFieldNameSuffix());
416
                        VariableTree staticField = tm.Variable(mods, instance, nestedId, null); //NOI18N
417
                        members.add(staticField);
418
                        members.add(gu.createGetter(staticField));
419
                        members.add(gu.createSetter(ct, staticField));
420
                        ClassTree newCT = gu.insertClassMembers(ct, members);
421
                        copy.rewrite(ct, newCT);
422
                    }
423
                });
424
                result.commit();
425
                final Reformat reformat = Reformat.get(doc);
426
                reformat.lock();
427
                try {
428
                    if (doc instanceof BaseDocument) {
429
                        ((BaseDocument) doc).runAtomicAsUser(new Runnable() {
430
                            @Override
431
                            public void run() {
432
                                try {
433
                                    reformat.reformat(0, doc.getLength());
434
                                } catch (BadLocationException ble) {
435
                                }
436
                            }
437
                        });
438
                    } else {
439
                        reformat.reformat(0, doc.getLength());
440
                    }
441
                } finally {
442
                    reformat.unlock();
443
                }
444
                DataObject dataObject = DataObject.find(source.getFileObject());
445
                SaveCookie sc = dataObject.getLookup().lookup(SaveCookie.class);
446
                if (sc != null) {
447
                    sc.save();
448
                }
449
            } catch (Exception ex) {
450
            }
451
            jep.setIgnoreRepaint(false);
452
            jep.scrollRectToVisible(new Rectangle(0, 0, 10, 10));
453
            jep.repaint(100);
454
        }
455
456
        private static class Element {
457
458
            private boolean isStatic;
459
            private ElementKind kind;
460
461
            @Override
462
            public String toString() {
463
                return (isStatic ? NbBundle.getMessage(FmtNaming.class, "VAL_gen_STATIC") + " " : "") //NOI18N
464
                       + NbBundle.getMessage(FmtNaming.class, "VAL_gen_" + kind.name()); //NOI18N
465
            }
466
        }
467
468
        private static class Visibility {
469
470
            private String kind;
471
472
            @Override
473
            public String toString() {
474
                return NbBundle.getMessage(FmtNaming.class, "VAL_gen_" + kind); //NOI18N
475
            }
476
        }
477
    }
478
}
(-)a/refactoring.java/nbproject/project.xml (-1 / +1 lines)
Lines 116-122 Link Here
116
                    <build-prerequisite/>
116
                    <build-prerequisite/>
117
                    <compile-dependency/>
117
                    <compile-dependency/>
118
                    <run-dependency>
118
                    <run-dependency>
119
                        <specification-version>0.110</specification-version>
119
                        <specification-version>0.122</specification-version>
120
                    </run-dependency>
120
                    </run-dependency>
121
                </dependency>
121
                </dependency>
122
                <dependency>
122
                <dependency>
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/RefactoringUtils.java (-34 / +48 lines)
Lines 56-64 Link Here
56
import javax.lang.model.element.ExecutableElement;
56
import javax.lang.model.element.ExecutableElement;
57
import javax.lang.model.element.Modifier;
57
import javax.lang.model.element.Modifier;
58
import javax.lang.model.element.TypeElement;
58
import javax.lang.model.element.TypeElement;
59
import javax.lang.model.element.VariableElement;
59
import javax.lang.model.type.*;
60
import javax.lang.model.type.*;
60
import javax.lang.model.util.ElementFilter;
61
import javax.lang.model.util.ElementFilter;
61
import javax.lang.model.util.Types;
62
import javax.lang.model.util.Types;
63
import javax.swing.text.Document;
62
import org.netbeans.api.annotations.common.NullUnknown;
64
import org.netbeans.api.annotations.common.NullUnknown;
63
import org.netbeans.api.java.classpath.ClassPath;
65
import org.netbeans.api.java.classpath.ClassPath;
64
import org.netbeans.api.java.classpath.ClassPath.Entry;
66
import org.netbeans.api.java.classpath.ClassPath.Entry;
Lines 90-96 Link Here
90
92
91
    private static final String JAVA_MIME_TYPE = "text/x-java"; // NOI18N
93
    private static final String JAVA_MIME_TYPE = "text/x-java"; // NOI18N
92
    private static final Logger LOG = Logger.getLogger(RefactoringUtils.class.getName());
94
    private static final Logger LOG = Logger.getLogger(RefactoringUtils.class.getName());
93
    private static final RequestProcessor RP = new RequestProcessor(RefactoringUtils.class.getName(), 1, false, false);
94
95
95
    /**
96
    /**
96
     * Get all overriding methods for given ExecutableElement
97
     * Get all overriding methods for given ExecutableElement
Lines 195-200 Link Here
195
        }
196
        }
196
        return result;
197
        return result;
197
    }
198
    }
199
    
200
    public static CodeStyle getCodeStyle(CompilationInfo info) {
201
        if (info != null) {
202
            try {
203
                Document doc = info.getDocument();
204
                if (doc != null) {
205
                    CodeStyle cs = (CodeStyle)doc.getProperty(CodeStyle.class);
206
                    return cs != null ? cs : CodeStyle.getDefault(doc);
207
                }
208
            } catch (IOException ioe) {
209
                // ignore
210
            }
211
212
            FileObject file = info.getFileObject();
213
            if (file != null) {
214
                return CodeStyle.getDefault(file);
215
            }
216
        }
217
218
        return CodeStyle.getDefault((Document)null);
219
    }
198
220
199
    /**
221
    /**
200
     *
222
     *
Lines 815-825 Link Here
815
        }
837
        }
816
    }
838
    }
817
839
818
    private static String getString(String key) {
819
        return NbBundle.getMessage(RefactoringUtils.class, key);
820
    }
821
822
823
    //XXX: copied from SourceUtils.addImports. Ideally, should be on one place only:
840
    //XXX: copied from SourceUtils.addImports. Ideally, should be on one place only:
824
    public static CompilationUnitTree addImports(CompilationUnitTree cut, List<String> toImport, TreeMaker make)
841
    public static CompilationUnitTree addImports(CompilationUnitTree cut, List<String> toImport, TreeMaker make)
825
            throws IOException {
842
            throws IOException {
Lines 902-908 Link Here
902
    }
919
    }
903
920
904
    public static boolean isSetter(CompilationInfo info, ExecutableElement el, Element propertyElement) {
921
    public static boolean isSetter(CompilationInfo info, ExecutableElement el, Element propertyElement) {
905
        String setterName = getSetterName(propertyElement.getSimpleName().toString());
922
        CodeStyle codeStyle = getCodeStyle(info);
923
        String setterName = CodeStyleUtils.computeSetterName(
924
                propertyElement.getSimpleName(),
925
                propertyElement.getModifiers().contains(Modifier.STATIC),
926
                codeStyle);
906
927
907
        return el.getSimpleName().contentEquals(setterName)
928
        return el.getSimpleName().contentEquals(setterName)
908
                && el.getReturnType().getKind() == TypeKind.VOID
929
                && el.getReturnType().getKind() == TypeKind.VOID
Lines 911-949 Link Here
911
    }
932
    }
912
933
913
    public static boolean isGetter(CompilationInfo info, ExecutableElement el, Element propertyElement) {
934
    public static boolean isGetter(CompilationInfo info, ExecutableElement el, Element propertyElement) {
914
        String getterName = getGetterName(propertyElement.getSimpleName().toString());
935
        CodeStyle codeStyle = getCodeStyle(info);
936
        String getterName = CodeStyleUtils.computeGetterName(
937
                propertyElement.getSimpleName(),
938
                propertyElement.asType().getKind() == TypeKind.BOOLEAN,
939
                propertyElement.getModifiers().contains(Modifier.STATIC),
940
                codeStyle);
915
        return el.getSimpleName().contentEquals(getterName)
941
        return el.getSimpleName().contentEquals(getterName)
916
                && info.getTypes().isSameType(el.getReturnType(),propertyElement.asType())
942
                && info.getTypes().isSameType(el.getReturnType(),propertyElement.asType())
917
                && el.getParameters().isEmpty();
943
                && el.getParameters().isEmpty();
918
    }
944
    }
945
    
946
    public static String removeFieldPrefixSuffix(Element var, CodeStyle cs) {
947
        boolean isStatic = var.getModifiers().contains(Modifier.STATIC);
948
        return CodeStyleUtils.removePrefixSuffix(var.getSimpleName(),
949
                isStatic ? cs.getStaticFieldNamePrefix() : cs.getFieldNamePrefix(),
950
                isStatic ? cs.getStaticFieldNameSuffix() : cs.getFieldNameSuffix());
951
    }
952
    
953
    public static String addParamPrefixSuffix(CharSequence name, CodeStyle cs) {
954
        return CodeStyleUtils.addPrefixSuffix(name,
955
                cs.getParameterNamePrefix(),
956
                cs.getParameterNameSuffix());
957
    }
919
958
920
    public static String getTestMethodName(String propertyName) {
959
    public static String getTestMethodName(String propertyName) {
921
	return "test" + capitalizeFirstLetter(propertyName); //NOI18N
960
	return "test" + CodeStyleUtils.getCapitalizedName(propertyName); //NOI18N
922
    }
923
924
    public static String getGetterName(String propertyName) {
925
        return "get" + capitalizeFirstLetter(propertyName); //NOI18N
926
    }
927
928
    public static String getSetterName(String propertyName) {
929
        return "set" + capitalizeFirstLetter(propertyName); //NOI18N
930
    }
931
932
    /**
933
     * Utility method capitalizes the first letter of string, used to generate
934
     * method names for patterns
935
     *
936
     * @param str The string for capitalization.
937
     * @return String with the first letter capitalized.
938
     */
939
    private static String capitalizeFirstLetter(String str) {
940
        if (str == null || str.length() <= 0) {
941
            return str;
942
        }
943
944
        char chars[] = str.toCharArray();
945
        chars[0] = Character.toUpperCase(chars[0]);
946
        return new String(chars);
947
    }
961
    }
948
962
949
    public static boolean isWeakerAccess(Set<Modifier> modifiers, Set<Modifier> modifiers0) {
963
    public static boolean isWeakerAccess(Set<Modifier> modifiers, Set<Modifier> modifiers0) {
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/EncapsulateFieldRefactoringPlugin.java (-73 / +26 lines)
Lines 97-103 Link Here
97
    private static Set<Modifier> accessModifiers = EnumSet.of(Modifier.PRIVATE, Modifier.PROTECTED, Modifier.PUBLIC);
97
    private static Set<Modifier> accessModifiers = EnumSet.of(Modifier.PRIVATE, Modifier.PROTECTED, Modifier.PUBLIC);
98
    private static List<Modifier> MODIFIERS = Arrays.asList(Modifier.PRIVATE, null, Modifier.PROTECTED, Modifier.PUBLIC);
98
    private static List<Modifier> MODIFIERS = Arrays.asList(Modifier.PRIVATE, null, Modifier.PROTECTED, Modifier.PUBLIC);
99
    private final EncapsulateFieldRefactoring refactoring;
99
    private final EncapsulateFieldRefactoring refactoring;
100
    public static final String CLASS_FIELD_PREFIX = "_"; // NOI18N
100
101
    /**
101
    /**
102
     * path in source with field declaration; refactoring.getSelectedObject()
102
     * path in source with field declaration; refactoring.getSelectedObject()
103
     * may contain path to a reference
103
     * may contain path to a reference
Lines 390-444 Link Here
390
        return false;
390
        return false;
391
    }
391
    }
392
392
393
    /**
394
     * Removes the class field prefix from the identifer of a field. For
395
     * example, if the class field prefix is "_", the identifier "_name" is
396
     * stripped to become "name".
397
     *
398
     * @param identifierString The identifer to strip.
399
     * @return The stripped identifier.
400
     */
401
    private static String stripPrefix(String identifierString) {
402
        String stripped;
403
        if (identifierString.startsWith(CLASS_FIELD_PREFIX) && identifierString.length() > 1) {
404
            stripped = identifierString.substring(CLASS_FIELD_PREFIX.length());
405
        } else {
406
            stripped = identifierString;
407
        }
408
        return stripped;
409
    }
410
411
    private static StringBuilder getCapitalizedName(VariableElement field) {
412
        StringBuilder name = new StringBuilder(stripPrefix(field.getSimpleName().toString()));
413
414
        //Beans naming convention, #165241
415
        if (name.length() > 1 && Character.isUpperCase(name.charAt(1))) {
416
            return name;
417
        }
418
419
        name.setCharAt(0, Character.toUpperCase(name.charAt(0)));
420
        return name;
421
    }
422
423
    public static String computeSetterName(VariableElement field) {
424
        StringBuilder name = getCapitalizedName(field);
425
426
        name.insert(0, "set"); //NOI18N
427
        return name.toString();
428
    }
429
430
    public static String computeGetterName(VariableElement field) {
431
        StringBuilder name = getCapitalizedName(field);
432
433
        if (TypeKind.BOOLEAN == field.asType().getKind()) { // XXX check autoboxing???
434
            name.insert(0, "is"); //NOI18N
435
        } else {
436
            name.insert(0, "get"); //NOI18N
437
        }
438
439
        return name.toString();
440
    }
441
442
    @Override
393
    @Override
443
    public Problem prepare(RefactoringElementsBag bag) {
394
    public Problem prepare(RefactoringElementsBag bag) {
444
395
Lines 605-628 Link Here
605
                    ClassTree nct = node;
556
                    ClassTree nct = node;
606
                    List<Tree> newMembers = new ArrayList<Tree>();
557
                    List<Tree> newMembers = new ArrayList<Tree>();
607
                    int getterIdx = 0;
558
                    int getterIdx = 0;
608
                        VariableTree pcs = null;
559
                    VariableTree pcs = null;
609
                        if (descs.get(0).refactoring.isGeneratePropertyChangeSupport()) {
560
                    if (descs.get(0).refactoring.isGeneratePropertyChangeSupport()) {
610
                            pcs = getPropertyChangeSupport(clazz, "java.beans.PropertyChangeSupport"); //NOI18N
561
                        pcs = getPropertyChangeSupport(clazz, "java.beans.PropertyChangeSupport"); //NOI18N
611
                            if (pcs == null) {
562
                        if (pcs == null) {
612
                                pcs = createPropertyChangeSupport("java.beans.PropertyChangeSupport", "propertyChangeSupport");//NOI18N
563
                            pcs = createPropertyChangeSupport("java.beans.PropertyChangeSupport", "propertyChangeSupport");//NOI18N
613
                                newMembers.add(pcs);
564
                            newMembers.add(pcs);
614
                            }
615
                        }
565
                        }
566
                    }
616
567
617
                        VariableTree vcs = null;
568
                    VariableTree vcs = null;
618
                        if (descs.get(0).refactoring.isGenerateVetoableChangeSupport()) {
569
                    if (descs.get(0).refactoring.isGenerateVetoableChangeSupport()) {
619
                            vcs = getPropertyChangeSupport(clazz, "java.beans.VetoableChangeSupport");//NOI18N
570
                        vcs = getPropertyChangeSupport(clazz, "java.beans.VetoableChangeSupport");//NOI18N
620
                            if (vcs == null) {
571
                        if (vcs == null) {
621
                                vcs = createPropertyChangeSupport("java.beans.VetoableChangeSupport", "vetoableChangeSupport");//NOI18N
572
                            vcs = createPropertyChangeSupport("java.beans.VetoableChangeSupport", "vetoableChangeSupport");//NOI18N
622
                                newMembers.add(vcs);
573
                            newMembers.add(vcs);
623
                            }
624
                        }
574
                        }
625
                        
575
                    }
576
                    CodeStyle cs = RefactoringUtils.getCodeStyle(workingCopy);
626
                    for (EncapsulateDesc desc : descs) {
577
                    for (EncapsulateDesc desc : descs) {
627
                        VariableTree propName = createPropName(clazz, desc);
578
                        VariableTree propName = createPropName(clazz, desc);
628
                        if (pcs!=null) {
579
                        if (pcs!=null) {
Lines 633-638 Link Here
633
                                desc.refactoring.getGetterName(),
584
                                desc.refactoring.getGetterName(),
634
                                desc.refactoring.getSetterName(),
585
                                desc.refactoring.getSetterName(),
635
                                desc.refactoring.getMethodModifiers(),
586
                                desc.refactoring.getMethodModifiers(),
587
                                cs,
636
                                pcs,
588
                                pcs,
637
                                vcs,
589
                                vcs,
638
                                propName);
590
                                propName);
Lines 989-1005 Link Here
989
        }
941
        }
990
942
991
        private MethodTree[] createGetterAndSetter(
943
        private MethodTree[] createGetterAndSetter(
992
                VariableElement field, String getterName,
944
                VariableElement field, String getterName, String setterName,
993
                String setterName, Set<Modifier> useModifiers,
945
                Set<Modifier> useModifiers, CodeStyle cs,
994
                VariableTree propertyChange, VariableTree vetoableChange, VariableTree propName) {
946
                VariableTree propertyChange, VariableTree vetoableChange, VariableTree propName) {
995
996
997
            String fieldName = field.getSimpleName().toString();
998
            boolean staticMod = field.getModifiers().contains(Modifier.STATIC);
947
            boolean staticMod = field.getModifiers().contains(Modifier.STATIC);
948
            String fieldName = CodeStyleUtils.removePrefixSuffix(field.getSimpleName(),
949
                    staticMod ? cs.getStaticFieldNamePrefix() : cs.getFieldNamePrefix(),
950
                    staticMod ? cs.getStaticFieldNameSuffix() : cs.getFieldNameSuffix());
951
            
999
            String longName = (staticMod ? "" : "this.") + fieldName;//NOI18N
952
            String longName = (staticMod ? "" : "this.") + fieldName;//NOI18N
1000
            String oldName = "old" + getCapitalizedName(field);//NOI18N
953
            String oldName = "old" + CodeStyleUtils.getCapitalizedName(fieldName);//NOI18N
1001
            String parName = staticMod ? "a" + getCapitalizedName(field) : Utilities.isJavaIdentifier(stripPrefix(fieldName)) ? stripPrefix(fieldName) : fieldName; //NOI18N
954
            String parName = staticMod ? "a" + CodeStyleUtils.getCapitalizedName(fieldName) : fieldName; //NOI18N
1002
            String getterBody = "{return " + fieldName + ";}"; //NOI18N
955
            String getterBody = "{return " + field.getSimpleName() + ";}"; //NOI18N
1003
            StringBuilder setterBody = new StringBuilder();
956
            StringBuilder setterBody = new StringBuilder();
1004
            setterBody.append("{");//NOI18N
957
            setterBody.append("{");//NOI18N
1005
958
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/IntroduceLocalExtensionTransformer.java (-13 / +18 lines)
Lines 58-63 Link Here
58
import javax.lang.model.util.Types;
58
import javax.lang.model.util.Types;
59
import org.netbeans.api.java.source.*;
59
import org.netbeans.api.java.source.*;
60
import org.netbeans.modules.refactoring.api.Problem;
60
import org.netbeans.modules.refactoring.api.Problem;
61
import org.netbeans.modules.refactoring.java.RefactoringUtils;
61
import org.netbeans.modules.refactoring.java.api.IntroduceLocalExtensionRefactoring;
62
import org.netbeans.modules.refactoring.java.api.IntroduceLocalExtensionRefactoring;
62
import org.netbeans.modules.refactoring.java.api.IntroduceLocalExtensionRefactoring.Equality;
63
import org.netbeans.modules.refactoring.java.api.IntroduceLocalExtensionRefactoring.Equality;
63
import org.netbeans.modules.refactoring.java.spi.RefactoringVisitor;
64
import org.netbeans.modules.refactoring.java.spi.RefactoringVisitor;
Lines 74-79 Link Here
74
public class IntroduceLocalExtensionTransformer extends RefactoringVisitor {
75
public class IntroduceLocalExtensionTransformer extends RefactoringVisitor {
75
76
76
    private static final Logger LOG = Logger.getLogger(IntroduceLocalExtensionTransformer.class.getName());
77
    private static final Logger LOG = Logger.getLogger(IntroduceLocalExtensionTransformer.class.getName());
78
    private static final String DELEGATE = "delegate"; //NOI18N
77
    private final IntroduceLocalExtensionRefactoring refactoring;
79
    private final IntroduceLocalExtensionRefactoring refactoring;
78
    private Problem problem;
80
    private Problem problem;
79
    private String fqn;
81
    private String fqn;
Lines 96-101 Link Here
96
            fqn = packageName + '.' + name;
98
            fqn = packageName + '.' + name;
97
99
98
            GeneratorUtilities genUtils = GeneratorUtilities.get(workingCopy);
100
            GeneratorUtilities genUtils = GeneratorUtilities.get(workingCopy);
101
            CodeStyle cs = RefactoringUtils.getCodeStyle(workingCopy);
99
102
100
            TypeElement source = (TypeElement) refactoring.getRefactoringSource().lookup(TreePathHandle.class).getElementHandle().resolve(workingCopy);
103
            TypeElement source = (TypeElement) refactoring.getRefactoringSource().lookup(TreePathHandle.class).getElementHandle().resolve(workingCopy);
101
104
Lines 112-120 Link Here
112
115
113
            if (wrap && noInterface) {
116
            if (wrap && noInterface) {
114
                Tree type = make.Type(source.asType());
117
                Tree type = make.Type(source.asType());
115
                VariableTree field = make.Variable(make.Modifiers(EnumSet.of(Modifier.PRIVATE)), "delegate", type, null); //NOI18N
118
                VariableTree field = make.Variable(make.Modifiers(EnumSet.of(Modifier.PRIVATE)), DELEGATE, type, null); //NOI18N
116
                members.add(0, field);
119
                members.add(0, field);
117
                addFields(source, genUtils, members);
120
                addFields(source, cs, members);
118
            }
121
            }
119
122
120
            if (wrap && noInterface) {
123
            if (wrap && noInterface) {
Lines 159-165 Link Here
159
        return super.scan(tree, p);
162
        return super.scan(tree, p);
160
    }
163
    }
161
164
162
    private void addFields(TypeElement source, GeneratorUtilities genUtils, List<Tree> members) throws IllegalStateException {
165
    private void addFields(TypeElement source, CodeStyle cs, List<Tree> members) throws IllegalStateException {
163
        for (VariableElement field : ElementFilter.fieldsIn(workingCopy.getElements().getAllMembers(source))) {
166
        for (VariableElement field : ElementFilter.fieldsIn(workingCopy.getElements().getAllMembers(source))) {
164
            if (!field.getModifiers().contains(Modifier.NATIVE)
167
            if (!field.getModifiers().contains(Modifier.NATIVE)
165
                    && field.getModifiers().contains(Modifier.PUBLIC)
168
                    && field.getModifiers().contains(Modifier.PUBLIC)
Lines 168-190 Link Here
168
                    VariableTree variable = make.Variable(field, make.QualIdent(field));
171
                    VariableTree variable = make.Variable(field, make.QualIdent(field));
169
                    members.add(0, variable);
172
                    members.add(0, variable);
170
                } else {
173
                } else {
171
                    String getterName = EncapsulateFieldRefactoringPlugin.computeGetterName(field);
174
                    MethodTree[] createdGetterAndSetter = createGetterAndSetter(field, field.getModifiers(), cs);
172
                    String setterName = EncapsulateFieldRefactoringPlugin.computeSetterName(field);
173
                    MethodTree[] createdGetterAndSetter = createGetterAndSetter(field, getterName, setterName, field.getModifiers());
174
                    ElementHandle<Element> fieldHandle = ElementHandle.create((Element) field);
175
                    ElementHandle<Element> fieldHandle = ElementHandle.create((Element) field);
175
                    getterSetterMap.put(fieldHandle, new String[]{getterName, setterName});
176
                    getterSetterMap.put(fieldHandle, new String[]{
177
                        createdGetterAndSetter[0].getName().toString(),
178
                        createdGetterAndSetter[1].getName().toString()});
176
                    members.addAll(Arrays.asList(createdGetterAndSetter));
179
                    members.addAll(Arrays.asList(createdGetterAndSetter));
177
                }
180
                }
178
            }
181
            }
179
        }
182
        }
180
    }
183
    }
181
184
182
    private MethodTree[] createGetterAndSetter(VariableElement field, String getterName, String setterName, Set<Modifier> useModifiers) {
185
    private MethodTree[] createGetterAndSetter(VariableElement field, Set<Modifier> useModifiers, CodeStyle cs) {
186
        boolean staticMod = field.getModifiers().contains(Modifier.STATIC);
187
        String getterName = CodeStyleUtils.computeGetterName(field.getSimpleName(), field.asType().getKind() == TypeKind.BOOLEAN, staticMod, cs);
188
        String setterName = CodeStyleUtils.computeSetterName(field.getSimpleName(), staticMod, cs);
183
        String fieldName = field.getSimpleName().toString();
189
        String fieldName = field.getSimpleName().toString();
184
        boolean staticMod = field.getModifiers().contains(Modifier.STATIC);
190
        String longName = (staticMod ? "" : "this.") + DELEGATE + "." + fieldName;//NOI18N
185
        String longName = staticMod ? "delegate." : "this.delegate." + fieldName;//NOI18N
186
        String parName = staticMod ? "a" + getCapitalizedName(field) : Utilities.isJavaIdentifier(stripPrefix(fieldName)) ? stripPrefix(fieldName) : fieldName; //NOI18N
191
        String parName = staticMod ? "a" + getCapitalizedName(field) : Utilities.isJavaIdentifier(stripPrefix(fieldName)) ? stripPrefix(fieldName) : fieldName; //NOI18N
187
        String getterBody = "{return delegate." + fieldName + ";}"; //NOI18N
192
        String getterBody = "{return " + DELEGATE + "." + fieldName + ";}"; //NOI18N
188
        StringBuilder setterBody = new StringBuilder();
193
        StringBuilder setterBody = new StringBuilder();
189
        setterBody.append("{");//NOI18N
194
        setterBody.append("{");//NOI18N
190
        setterBody.append(longName).append(" = ").append(parName).append(";"); //NOI18N
195
        setterBody.append(longName).append(" = ").append(parName).append(";"); //NOI18N
Lines 301-307 Link Here
301
                 *     return this.delegate.hashCode();
306
                 *     return this.delegate.hashCode();
302
                 * }
307
                 * }
303
                 */
308
                 */
304
                BlockTree body = make.Block(Collections.singletonList(make.Return(make.MethodInvocation(Collections.EMPTY_LIST, make.MemberSelect(make.Identifier("this.delegate"), "equals"), Collections.singletonList(make.MemberSelect(make.Identifier("o"), "delegate"))))), false); //NOI18N
309
                BlockTree body = make.Block(Collections.singletonList(make.Return(make.MethodInvocation(Collections.EMPTY_LIST, make.MemberSelect(make.Identifier("this.delegate"), "equals"), Collections.singletonList(make.MemberSelect(make.Identifier("o"), DELEGATE))))), false); //NOI18N
305
                MethodTree method = make.Method(make.Modifiers(EnumSet.of(Modifier.PUBLIC)),
310
                MethodTree method = make.Method(make.Modifiers(EnumSet.of(Modifier.PUBLIC)),
306
                        "equals" + refactoring.getNewName(), //NOI18N
311
                        "equals" + refactoring.getNewName(), //NOI18N
307
                        make.PrimitiveType(TypeKind.BOOLEAN),
312
                        make.PrimitiveType(TypeKind.BOOLEAN),
Lines 332-338 Link Here
332
                statements.add(
337
                statements.add(
333
                        make.If(make.InstanceOf(make.Identifier("o"), newSimpleTypeTree), make.Block(Collections.singletonList(make.ExpressionStatement(
338
                        make.If(make.InstanceOf(make.Identifier("o"), newSimpleTypeTree), make.Block(Collections.singletonList(make.ExpressionStatement(
334
                        make.Assignment(make.Identifier("target"),
339
                        make.Assignment(make.Identifier("target"),
335
                        make.MemberSelect(make.Parenthesized(make.TypeCast(newSimpleTypeTree, make.Identifier("o"))), "delegate")))), false), null));
340
                        make.MemberSelect(make.Parenthesized(make.TypeCast(newSimpleTypeTree, make.Identifier("o"))), DELEGATE)))), false), null));
336
                statements.add(make.Return(make.MethodInvocation(Collections.EMPTY_LIST, make.Identifier("this.delegate.equals"), Collections.singletonList(make.Identifier("target")))));
341
                statements.add(make.Return(make.MethodInvocation(Collections.EMPTY_LIST, make.Identifier("this.delegate.equals"), Collections.singletonList(make.Identifier("target")))));
337
                BlockTree body = make.Block(statements, false);
342
                BlockTree body = make.Block(statements, false);
338
                MethodTree method = make.Method(make.Modifiers(EnumSet.of(Modifier.PUBLIC)),
343
                MethodTree method = make.Method(make.Modifiers(EnumSet.of(Modifier.PUBLIC)),
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavaPluginUtils.java (-54 / +108 lines)
Lines 53-60 Link Here
53
import javax.lang.model.SourceVersion;
53
import javax.lang.model.SourceVersion;
54
import javax.lang.model.element.Element;
54
import javax.lang.model.element.Element;
55
import javax.lang.model.element.ElementKind;
55
import javax.lang.model.element.ElementKind;
56
import javax.lang.model.element.ExecutableElement;
57
import javax.lang.model.element.Modifier;
56
import javax.lang.model.element.TypeElement;
58
import javax.lang.model.element.TypeElement;
59
import javax.lang.model.element.VariableElement;
57
import javax.lang.model.type.*;
60
import javax.lang.model.type.*;
61
import javax.lang.model.util.Types;
58
import org.netbeans.api.java.classpath.ClassPath;
62
import org.netbeans.api.java.classpath.ClassPath;
59
import org.netbeans.api.java.source.ClasspathInfo.PathKind;
63
import org.netbeans.api.java.source.ClasspathInfo.PathKind;
60
import org.netbeans.api.java.source.*;
64
import org.netbeans.api.java.source.*;
Lines 296-313 Link Here
296
        return source;
300
        return source;
297
    }
301
    }
298
    
302
    
303
    public static boolean hasGetter(CompilationInfo info, TypeElement typeElement, VariableElement field, Map<String, List<ExecutableElement>> methods, CodeStyle cs) {
304
        CharSequence name = field.getSimpleName();
305
        assert name.length() > 0;
306
        TypeMirror type = field.asType();
307
        boolean isStatic = field.getModifiers().contains(Modifier.STATIC);
308
        String getterName = CodeStyleUtils.computeGetterName(name, type.getKind() == TypeKind.BOOLEAN, isStatic, cs);
309
        Types types = info.getTypes();
310
        List<ExecutableElement> candidates = methods.get(getterName);
311
        if (candidates != null) {
312
            for (ExecutableElement candidate : candidates) {
313
                if ((!candidate.getModifiers().contains(Modifier.ABSTRACT) || candidate.getEnclosingElement() == typeElement)
314
                        && candidate.getParameters().isEmpty()
315
                        && types.isSameType(candidate.getReturnType(), type))
316
                    return true;
317
            }
318
        }
319
        return false;
320
    }
321
    
322
    public static boolean hasSetter(CompilationInfo info, TypeElement typeElement, VariableElement field, Map<String, List<ExecutableElement>> methods, CodeStyle cs) {
323
        CharSequence name = field.getSimpleName();
324
        assert name.length() > 0;
325
        TypeMirror type = field.asType();
326
        boolean isStatic = field.getModifiers().contains(Modifier.STATIC);
327
        String setterName = CodeStyleUtils.computeSetterName(name, isStatic, cs);
328
        Types types = info.getTypes();
329
        List<ExecutableElement> candidates = methods.get(setterName);
330
        if (candidates != null) {
331
            for (ExecutableElement candidate : candidates) {
332
                if ((!candidate.getModifiers().contains(Modifier.ABSTRACT) || candidate.getEnclosingElement() == typeElement)
333
                        && candidate.getReturnType().getKind() == TypeKind.VOID
334
                        && candidate.getParameters().size() == 1
335
                        && types.isSameType(candidate.getParameters().get(0).asType(), type))
336
                    return true;
337
            }
338
        }
339
        return false;
340
    }
341
    
299
    //<editor-fold defaultstate="collapsed" desc="TODO: Copy from org.netbeans.modules.java.hints.errors.Utilities">
342
    //<editor-fold defaultstate="collapsed" desc="TODO: Copy from org.netbeans.modules.java.hints.errors.Utilities">
300
    public static final String DEFAULT_NAME = "par"; // NOI18N
343
    public static final String DEFAULT_NAME = "par"; // NOI18N
301
    public static String makeNameUnique(CompilationInfo info, Scope s, String name) {
344
    public static String makeNameUnique(CompilationInfo info, Scope s, String name) {
302
        return makeNameUnique(info, s, name, Collections.EMPTY_LIST);
345
        return makeNameUnique(info, s, name, Collections.EMPTY_LIST, null, null);
303
    }
346
    }
347
    
304
    public static String makeNameUnique(CompilationInfo info, Scope s, String name, List<String> definedIds) {
348
    public static String makeNameUnique(CompilationInfo info, Scope s, String name, List<String> definedIds) {
349
        return makeNameUnique(info, s, name, definedIds, null, null);
350
    }
351
    
352
    public static String makeNameUnique(CompilationInfo info, Scope s, String name, String prefix, String suffix) {
353
        return makeNameUnique(info, s, name, Collections.EMPTY_LIST, prefix, suffix);
354
    }
355
    
356
    public static String makeNameUnique(CompilationInfo info, Scope s, String name, List<String> definedIds, String prefix, String suffix) {
357
        boolean cont;
358
        String proposedName;
359
        name = CodeStyleUtils.addPrefixSuffix(name, prefix, null);
305
        int counter = 0;
360
        int counter = 0;
306
        boolean cont = true;
361
        do {
307
        String proposedName = name;
362
            proposedName = name + (counter != 0 ? String.valueOf(counter) : "") + safeString(suffix);
308
        
309
        while (cont) {
310
            proposedName = (counter != 0 ? name + String.valueOf(counter) : name);
311
            
363
            
312
            cont = false;
364
            cont = false;
313
            
365
            
Lines 320-339 Link Here
320
                    }
372
                    }
321
                }
373
                }
322
                for (Element e : info.getElementUtilities().getLocalMembersAndVars(s, new VariablesFilter())) {
374
                for (Element e : info.getElementUtilities().getLocalMembersAndVars(s, new VariablesFilter())) {
323
                    if (proposedName.equals(e.getSimpleName().toString())) {
375
                if (proposedName.equals(e.getSimpleName().toString())) {
324
                        counter++;
376
                    counter++;
325
                        cont = true;
377
                    cont = true;
326
                        break;
378
                    break;
327
                    }
379
                    }
328
                }
380
                }
329
            }
381
            }
330
        }
382
        } while(cont);
331
        
383
        
332
        return proposedName;
384
        return proposedName;
333
    }
385
    }
334
    
386
    
335
    public static String getName(Tree et) {
387
    private static String safeString(String str) {
336
        return adjustName(getNameRaw(et));
388
        return str == null ? "" : str;
337
    }
389
    }
338
    
390
    
339
    public static String getName(TypeMirror tm) {
391
    public static String getName(TypeMirror tm) {
Lines 352-384 Link Here
352
        }
404
        }
353
    }
405
    }
354
    
406
    
407
    public static String getName(ExpressionTree et) {
408
        return getName((Tree) et);
409
    }
410
    
411
    public static String getName(Tree et) {
412
        return adjustName(getNameRaw(et));
413
    }
414
    
355
    private static String getNameRaw(Tree et) {
415
    private static String getNameRaw(Tree et) {
356
        if (et == null) {
416
        if (et == null)
357
            return null;
417
            return null;
358
        }
418
359
        
360
        switch (et.getKind()) {
419
        switch (et.getKind()) {
361
            case IDENTIFIER:
420
        case IDENTIFIER:
362
                return ((IdentifierTree) et).getName().toString();
421
            return ((IdentifierTree) et).getName().toString();
363
            case METHOD_INVOCATION:
422
        case METHOD_INVOCATION:
364
                return getName(((MethodInvocationTree) et).getMethodSelect());
423
            return getNameRaw(((MethodInvocationTree) et).getMethodSelect());
365
            case MEMBER_SELECT:
424
        case MEMBER_SELECT:
366
                return ((MemberSelectTree) et).getIdentifier().toString();
425
            return ((MemberSelectTree) et).getIdentifier().toString();
367
            case NEW_CLASS:
426
        case NEW_CLASS:
368
                return firstToLower(getName(((NewClassTree) et).getIdentifier()));
427
            return firstToLower(getNameRaw(((NewClassTree) et).getIdentifier()));
369
            case PARAMETERIZED_TYPE:
428
        case PARAMETERIZED_TYPE:
370
                return firstToLower(getName(((ParameterizedTypeTree) et).getType()));
429
            return firstToLower(getNameRaw(((ParameterizedTypeTree) et).getType()));
371
            case STRING_LITERAL:
430
        case STRING_LITERAL:
372
                String name = guessLiteralName((String) ((LiteralTree) et).getValue());
431
            String name = guessLiteralName((String) ((LiteralTree) et).getValue());
373
                if(name == null) {
432
            if(name == null) {
374
                    return firstToLower(String.class.getSimpleName());
433
                return firstToLower(String.class.getSimpleName());
375
                } else {
434
            } else {
376
                    return firstToLower(name);
435
                return firstToLower(name);
377
                }
436
            }
378
            case VARIABLE:
437
        case VARIABLE:
379
                return ((VariableTree) et).getName().toString();
438
            return ((VariableTree) et).getName().toString();
380
            default:
439
        default:
381
                return null;
440
            return null;
382
        }
441
        }
383
    }
442
    }
384
    
443
    
Lines 412-434 Link Here
412
        if (name.length() == 0) {
471
        if (name.length() == 0) {
413
            return null;
472
            return null;
414
        }
473
        }
415
        
474
416
        StringBuilder result = new StringBuilder();
475
        StringBuilder result = new StringBuilder();
417
        boolean toLower = true;
476
        boolean toLower = true;
418
        char last = Character.toLowerCase(name.charAt(0));
477
        char last = Character.toLowerCase(name.charAt(0));
419
        
478
420
        for (int i = 1; i < name.length(); i++) {
479
        for (int i = 1; i < name.length(); i++) {
421
            if (toLower && Character.isUpperCase(name.charAt(i))) {
480
            if (toLower && (Character.isUpperCase(name.charAt(i)) || name.charAt(i) == '_')) {
422
                result.append(Character.toLowerCase(last));
481
                result.append(Character.toLowerCase(last));
423
            } else {
482
            } else {
424
                result.append(last);
483
                result.append(last);
425
                toLower = false;
484
                toLower = false;
426
            }
485
            }
427
            last = name.charAt(i);
486
            last = name.charAt(i);
428
            
487
429
        }
488
        }
430
        
489
431
        result.append(last);
490
        result.append(toLower ? Character.toLowerCase(last) : last);
432
        
491
        
433
        if (SourceVersion.isKeyword(result)) {
492
        if (SourceVersion.isKeyword(result)) {
434
            return "a" + name;
493
            return "a" + name;
Lines 438-462 Link Here
438
    }
497
    }
439
    
498
    
440
    private static String guessLiteralName(String str) {
499
    private static String guessLiteralName(String str) {
441
        StringBuilder sb = new StringBuilder();
500
        if(str.isEmpty()) {
442
        if(str.length() == 0) {
443
            return null;
501
            return null;
444
        }
502
        }
445
        char first = str.charAt(0);
446
        if(Character.isJavaIdentifierStart(str.charAt(0))) {
447
            sb.append(first);
448
        }
449
        
503
        
450
        for (int i = 1; i < str.length(); i++) {
504
        StringBuilder sb = new StringBuilder();
505
506
        for (int i = 0; i < str.length(); i++) {
451
            char ch = str.charAt(i);
507
            char ch = str.charAt(i);
452
            if(ch == ' ') {
508
            if(ch == ' ') {
453
                sb.append('_');
509
                sb.append('_');
454
                continue;
510
            } else if (sb.length() == 0 ? Character.isJavaIdentifierStart(ch) : Character.isJavaIdentifierPart(ch)) {
455
            }
456
            if (Character.isJavaIdentifierPart(ch)) {
457
                sb.append(ch);
511
                sb.append(ch);
458
            }
512
            }
459
            if (i > 40) {
513
            if (sb.length() > 40) {
460
                break;
514
                break;
461
            }
515
            }
462
        }
516
        }
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/RenamePropertyRefactoringPlugin.java (-7 / +39 lines)
Lines 44-51 Link Here
44
import java.io.IOException;
44
import java.io.IOException;
45
import javax.lang.model.element.Element;
45
import javax.lang.model.element.Element;
46
import javax.lang.model.element.ExecutableElement;
46
import javax.lang.model.element.ExecutableElement;
47
import javax.lang.model.element.Modifier;
48
import javax.lang.model.element.Name;
47
import javax.lang.model.element.VariableElement;
49
import javax.lang.model.element.VariableElement;
50
import javax.lang.model.type.TypeKind;
48
import javax.lang.model.util.ElementFilter;
51
import javax.lang.model.util.ElementFilter;
52
import org.netbeans.api.java.source.CodeStyle;
53
import org.netbeans.api.java.source.CodeStyleUtils;
49
import org.netbeans.api.java.source.CompilationController;
54
import org.netbeans.api.java.source.CompilationController;
50
import org.netbeans.api.java.source.JavaSource;
55
import org.netbeans.api.java.source.JavaSource;
51
import org.netbeans.api.java.source.Task;
56
import org.netbeans.api.java.source.Task;
Lines 68-73 Link Here
68
73
69
    private RenameRefactoring refactoring;
74
    private RenameRefactoring refactoring;
70
    private TreePathHandle property;
75
    private TreePathHandle property;
76
    private CodeStyle codeStyle;
77
    private boolean isStatic;
78
    private boolean isBoolean;
71
    private RenameRefactoring getterDelegate;
79
    private RenameRefactoring getterDelegate;
72
    private RenameRefactoring setterDelegate;
80
    private RenameRefactoring setterDelegate;
73
    private RenameRefactoring parameterDelegate;
81
    private RenameRefactoring parameterDelegate;
Lines 122-142 Link Here
122
130
123
        Problem p = null;
131
        Problem p = null;
124
        if (getterDelegate != null) {
132
        if (getterDelegate != null) {
125
            getterDelegate.setNewName(RefactoringUtils.getGetterName(refactoring.getNewName()));
133
            String gettername = CodeStyleUtils.computeGetterName(
134
                                    refactoring.getNewName(), isBoolean, isStatic, codeStyle);
135
            getterDelegate.setNewName(gettername);
126
            p = JavaPluginUtils.chainProblems(p, getterDelegate.fastCheckParameters());
136
            p = JavaPluginUtils.chainProblems(p, getterDelegate.fastCheckParameters());
127
            if (p != null && p.isFatal()) {
137
            if (p != null && p.isFatal()) {
128
                return p;
138
                return p;
129
            }
139
            }
130
        }
140
        }
131
        if (setterDelegate != null) {
141
        if (setterDelegate != null) {
132
            setterDelegate.setNewName(RefactoringUtils.getSetterName(refactoring.getNewName()));
142
            String settername = CodeStyleUtils.computeSetterName(
143
                                    refactoring.getNewName(), isStatic, codeStyle);
144
            setterDelegate.setNewName(settername);
133
            p = JavaPluginUtils.chainProblems(p, setterDelegate.fastCheckParameters());
145
            p = JavaPluginUtils.chainProblems(p, setterDelegate.fastCheckParameters());
134
            if (p != null && p.isFatal()) {
146
            if (p != null && p.isFatal()) {
135
                return p;
147
                return p;
136
            }
148
            }
137
        }
149
        }
138
        if (parameterDelegate != null) {
150
        if (parameterDelegate != null) {
139
            parameterDelegate.setNewName(refactoring.getNewName());
151
            String newParam = RefactoringUtils.addParamPrefixSuffix(
152
                            CodeStyleUtils.removePrefixSuffix(
153
                            refactoring.getNewName(),
154
                            isStatic ? codeStyle.getStaticFieldNamePrefix() : codeStyle.getFieldNamePrefix(),
155
                            isStatic ? codeStyle.getStaticFieldNameSuffix() : codeStyle.getFieldNameSuffix()), codeStyle);
156
            parameterDelegate.setNewName(newParam);
140
            p = JavaPluginUtils.chainProblems(p, parameterDelegate.fastCheckParameters());
157
            p = JavaPluginUtils.chainProblems(p, parameterDelegate.fastCheckParameters());
141
            if (p != null && p.isFatal()) {
158
            if (p != null && p.isFatal()) {
142
                return p;
159
                return p;
Lines 224-245 Link Here
224
        }
241
        }
225
        try {
242
        try {
226
            getJavaSource(Phase.PREPARE).runUserActionTask(new Task<CompilationController>() {
243
            getJavaSource(Phase.PREPARE).runUserActionTask(new Task<CompilationController>() {
244
                private String propName;
227
245
228
                @Override
246
                @Override
229
                public void run(CompilationController p) throws Exception {
247
                public void run(CompilationController p) throws Exception {
230
                    p.toPhase(JavaSource.Phase.RESOLVED);
248
                    p.toPhase(JavaSource.Phase.RESOLVED);
249
                    codeStyle = RefactoringUtils.getCodeStyle(p);
231
                    Element propertyElement = property.resolveElement(p);
250
                    Element propertyElement = property.resolveElement(p);
251
                    isStatic = propertyElement.getModifiers().contains(Modifier.STATIC);
252
                    isBoolean = propertyElement.asType().getKind() == TypeKind.BOOLEAN;
253
                    propName = RefactoringUtils.removeFieldPrefixSuffix(propertyElement, codeStyle);
254
                    String paramName = RefactoringUtils.addParamPrefixSuffix(propName, codeStyle);
255
                    String newParam = RefactoringUtils.addParamPrefixSuffix(
256
                            CodeStyleUtils.removePrefixSuffix(
257
                            refactoring.getNewName(),
258
                            isStatic ? codeStyle.getStaticFieldNamePrefix() : codeStyle.getFieldNamePrefix(),
259
                            isStatic ? codeStyle.getStaticFieldNameSuffix() : codeStyle.getFieldNameSuffix()), codeStyle);
232
                    for (ExecutableElement el : ElementFilter.methodsIn(propertyElement.getEnclosingElement().getEnclosedElements())) {
260
                    for (ExecutableElement el : ElementFilter.methodsIn(propertyElement.getEnclosingElement().getEnclosedElements())) {
233
                        if (RefactoringUtils.isGetter(p, el, propertyElement)) {
261
                        if (RefactoringUtils.isGetter(p, el, propertyElement)) {
234
                            getterDelegate = new RenameRefactoring(Lookups.singleton(TreePathHandle.create(el, p)));
262
                            getterDelegate = new RenameRefactoring(Lookups.singleton(TreePathHandle.create(el, p)));
235
                            getterDelegate.setNewName(RefactoringUtils.getGetterName(refactoring.getNewName()));
263
                            String gettername = CodeStyleUtils.computeGetterName(
264
                                    refactoring.getNewName(), isBoolean, isStatic, codeStyle);
265
                            getterDelegate.setNewName(gettername);
236
                        } else if (RefactoringUtils.isSetter(p, el, propertyElement)) {
266
                        } else if (RefactoringUtils.isSetter(p, el, propertyElement)) {
237
                            setterDelegate = new RenameRefactoring(Lookups.singleton(TreePathHandle.create(el, p)));
267
                            setterDelegate = new RenameRefactoring(Lookups.singleton(TreePathHandle.create(el, p)));
238
                            setterDelegate.setNewName(RefactoringUtils.getSetterName(refactoring.getNewName()));
268
                            String settername = CodeStyleUtils.computeSetterName(
269
                                    refactoring.getNewName(), isStatic, codeStyle);
270
                            setterDelegate.setNewName(settername);
239
                            VariableElement par = el.getParameters().iterator().next();
271
                            VariableElement par = el.getParameters().iterator().next();
240
                            if (par.getSimpleName().contentEquals(propertyElement.getSimpleName())) {
272
                            if (par.getSimpleName().contentEquals(paramName)) {
241
                                parameterDelegate = new RenameRefactoring(Lookups.singleton(TreePathHandle.create(p.getTrees().getPath(par), p)));
273
                                parameterDelegate = new RenameRefactoring(Lookups.singleton(TreePathHandle.create(p.getTrees().getPath(par), p)));
242
                                parameterDelegate.setNewName(refactoring.getNewName());
274
                                parameterDelegate.setNewName(newParam);
243
                            }
275
                            }
244
                        }
276
                        }
245
                    }
277
                    }
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ChangeParametersPanel.java (-4 / +5 lines)
Lines 118-124 Link Here
118
    private boolean methodNameChanged;
118
    private boolean methodNameChanged;
119
    private boolean returnTypeChanged;
119
    private boolean returnTypeChanged;
120
    private boolean isConstructor;
120
    private boolean isConstructor;
121
    
121
    private final String paramname;
122
    
122
    
123
    @Override
123
    @Override
124
    public Component getComponent() {
124
    public Component getComponent() {
Lines 142-148 Link Here
142
    private static final String ACTION_INLINE_EDITOR = "invokeInlineEditor";  //NOI18N
142
    private static final String ACTION_INLINE_EDITOR = "invokeInlineEditor";  //NOI18N
143
143
144
    /** Creates new form ChangeMethodSignature */
144
    /** Creates new form ChangeMethodSignature */
145
    public ChangeParametersPanel(TreePathHandle refactoredObj, ChangeListener parent, ParameterInfo[] preConfiguration) {
145
    public ChangeParametersPanel(TreePathHandle refactoredObj, ChangeListener parent, ParameterInfo[] preConfiguration, CodeStyle cs) {
146
        returnTypeDocListener = new ReturnTypeDocListener();
146
        returnTypeDocListener = new ReturnTypeDocListener();
147
        methodNameDocListener = new MethodNameDocListener();
147
        methodNameDocListener = new MethodNameDocListener();
148
        this.refactoredObj = refactoredObj;
148
        this.refactoredObj = refactoredObj;
Lines 151-157 Link Here
151
        model = new ParamTableModel(columnNames, 0);
151
        model = new ParamTableModel(columnNames, 0);
152
        this.returnTypeAction = new ReturnTypeAction();
152
        this.returnTypeAction = new ReturnTypeAction();
153
        singleLineEditor = Utilities.createSingleLineEditor(MIME_JAVA);
153
        singleLineEditor = Utilities.createSingleLineEditor(MIME_JAVA);
154
        
154
        paramname = CodeStyleUtils.addPrefixSuffix("par", cs.getParameterNamePrefix(), cs.getParameterNameSuffix());
155
155
        initComponents();
156
        initComponents();
156
157
157
        InputMap im = paramTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
158
        InputMap im = paramTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
Lines 616-622 Link Here
616
    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
617
    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
617
        acceptEditedValue(); 
618
        acceptEditedValue(); 
618
        int rowCount = model.getRowCount();
619
        int rowCount = model.getRowCount();
619
        model.addRow(new Object[] { "Object", "par" + rowCount, "null", new Integer(-1), Boolean.TRUE }); // NOI18N
620
        model.addRow(new Object[] { "Object", paramname + rowCount, "null", new Integer(-1), Boolean.TRUE }); // NOI18N
620
        paramTable.scrollRectToVisible(paramTable.getCellRect(rowCount, 0, false));
621
        paramTable.scrollRectToVisible(paramTable.getCellRect(rowCount, 0, false));
621
        paramTable.changeSelection(rowCount, 0, false, false);
622
        paramTable.changeSelection(rowCount, 0, false, false);
622
        autoEdit(paramTable);
623
        autoEdit(paramTable);
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ChangeParametersUI.java (-3 / +6 lines)
Lines 57-62 Link Here
57
import javax.lang.model.type.TypeKind;
57
import javax.lang.model.type.TypeKind;
58
import javax.swing.event.ChangeListener;
58
import javax.swing.event.ChangeListener;
59
import org.netbeans.api.fileinfo.NonRecursiveFolder;
59
import org.netbeans.api.fileinfo.NonRecursiveFolder;
60
import org.netbeans.api.java.source.CodeStyle;
60
import org.netbeans.api.java.source.CompilationInfo;
61
import org.netbeans.api.java.source.CompilationInfo;
61
import org.netbeans.api.java.source.TreePathHandle;
62
import org.netbeans.api.java.source.TreePathHandle;
62
import org.netbeans.modules.refactoring.api.AbstractRefactoring;
63
import org.netbeans.modules.refactoring.api.AbstractRefactoring;
Lines 83-97 Link Here
83
    private boolean isMethod;
84
    private boolean isMethod;
84
    private ChangeParametersRefactoring.ParameterInfo[] preConfiguration;
85
    private ChangeParametersRefactoring.ParameterInfo[] preConfiguration;
85
    private Lookup lookup;
86
    private Lookup lookup;
87
    private CodeStyle cs;
86
    
88
    
87
    /** Creates a new instance of ChangeMethodSignatureRefactoring */
89
    /** Creates a new instance of ChangeMethodSignatureRefactoring */
88
    private ChangeParametersUI(TreePathHandle refactoredObj, CompilationInfo info, ChangeParametersRefactoring.ParameterInfo[] preConfiguration) {
90
    private ChangeParametersUI(TreePathHandle refactoredObj, CompilationInfo info, ParameterInfo[] preConfiguration, CodeStyle cs) {
89
        this.refactoring = new ChangeParametersRefactoring(refactoredObj);
91
        this.refactoring = new ChangeParametersRefactoring(refactoredObj);
90
        this.method = refactoredObj;
92
        this.method = refactoredObj;
91
        this.preConfiguration = preConfiguration;
93
        this.preConfiguration = preConfiguration;
92
        Element element = method.resolveElement(info);
94
        Element element = method.resolveElement(info);
93
        this.name = element.getSimpleName().toString();
95
        this.name = element.getSimpleName().toString();
94
        this.isMethod = element.getKind() == ElementKind.METHOD;
96
        this.isMethod = element.getKind() == ElementKind.METHOD;
97
        this.cs = cs;
95
    }
98
    }
96
99
97
    private ChangeParametersUI(Lookup lookup) {
100
    private ChangeParametersUI(Lookup lookup) {
Lines 126-132 Link Here
126
        }
129
        }
127
        
130
        
128
        return path != null
131
        return path != null
129
                ? new ChangeParametersUI(TreePathHandle.create(path, info), info, configuration)
132
                ? new ChangeParametersUI(TreePathHandle.create(path, info), info, configuration, CodeStyle.getDefault(info.getFileObject()))
130
                : null;
133
                : null;
131
    }
134
    }
132
    
135
    
Lines 148-154 Link Here
148
    @Override
151
    @Override
149
    public CustomRefactoringPanel getPanel(ChangeListener parent) {
152
    public CustomRefactoringPanel getPanel(ChangeListener parent) {
150
        if (panel == null) {
153
        if (panel == null) {
151
            panel = new ChangeParametersPanel(method, parent, preConfiguration);
154
            panel = new ChangeParametersPanel(method, parent, preConfiguration, cs);
152
        }
155
        }
153
        return panel;
156
        return panel;
154
    }
157
    }
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/EncapsulateFieldPanel.java (-2 / +6 lines)
Lines 52-57 Link Here
52
import java.io.IOException;
52
import java.io.IOException;
53
import java.util.*;
53
import java.util.*;
54
import javax.lang.model.element.*;
54
import javax.lang.model.element.*;
55
import javax.lang.model.type.TypeKind;
55
import javax.swing.*;
56
import javax.swing.*;
56
import javax.swing.event.ChangeListener;
57
import javax.swing.event.ChangeListener;
57
import javax.swing.event.TableModelEvent;
58
import javax.swing.event.TableModelEvent;
Lines 62-67 Link Here
62
import org.netbeans.api.java.source.*;
63
import org.netbeans.api.java.source.*;
63
import org.netbeans.api.java.source.ui.ElementHeaders;
64
import org.netbeans.api.java.source.ui.ElementHeaders;
64
import org.netbeans.modules.refactoring.java.RefactoringModule;
65
import org.netbeans.modules.refactoring.java.RefactoringModule;
66
import org.netbeans.modules.refactoring.java.RefactoringUtils;
65
import org.netbeans.modules.refactoring.java.api.MemberInfo;
67
import org.netbeans.modules.refactoring.java.api.MemberInfo;
66
import org.netbeans.modules.refactoring.java.plugins.EncapsulateFieldRefactoringPlugin;
68
import org.netbeans.modules.refactoring.java.plugins.EncapsulateFieldRefactoringPlugin;
67
import org.netbeans.modules.refactoring.java.ui.EncapsulateFieldsRefactoring.EncapsulateFieldInfo;
69
import org.netbeans.modules.refactoring.java.ui.EncapsulateFieldsRefactoring.EncapsulateFieldInfo;
Lines 188-195 Link Here
188
            TreePath fieldTPath = javac.getTrees().getPath(field);
190
            TreePath fieldTPath = javac.getTrees().getPath(field);
189
            boolean createGetter = fields !=null? fields.contains(TreePathHandle.create(field, javac)) : selectedElm == field ;
191
            boolean createGetter = fields !=null? fields.contains(TreePathHandle.create(field, javac)) : selectedElm == field ;
190
            boolean createSetter = createGetter && !field.getModifiers().contains(Modifier.FINAL);
192
            boolean createSetter = createGetter && !field.getModifiers().contains(Modifier.FINAL);
191
            String getName = EncapsulateFieldRefactoringPlugin.computeGetterName(field);
193
            CodeStyle cs = RefactoringUtils.getCodeStyle(javac);
192
            String setName = EncapsulateFieldRefactoringPlugin.computeSetterName(field);
194
            boolean staticMod = field.getModifiers().contains(Modifier.STATIC);
195
            String getName = CodeStyleUtils.computeGetterName(field.getSimpleName(), field.asType().getKind() == TypeKind.BOOLEAN, staticMod, cs);
196
            String setName = CodeStyleUtils.computeSetterName(field.getSimpleName(), staticMod, cs);
193
            model.addRow(new Object[] { 
197
            model.addRow(new Object[] { 
194
                MemberInfo.create(fieldTPath, javac),
198
                MemberInfo.create(fieldTPath, javac),
195
                createGetter ? Boolean.TRUE : Boolean.FALSE,                        
199
                createGetter ? Boolean.TRUE : Boolean.FALSE,                        
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/IntroduceParameterPanel.java (-1 / +9 lines)
Lines 59-64 Link Here
59
import javax.swing.text.Position;
59
import javax.swing.text.Position;
60
import org.netbeans.api.editor.DialogBinding;
60
import org.netbeans.api.editor.DialogBinding;
61
import org.netbeans.api.java.source.CancellableTask;
61
import org.netbeans.api.java.source.CancellableTask;
62
import org.netbeans.api.java.source.CodeStyle;
62
import org.netbeans.api.java.source.CompilationController;
63
import org.netbeans.api.java.source.CompilationController;
63
import org.netbeans.api.java.source.JavaSource;
64
import org.netbeans.api.java.source.JavaSource;
64
import org.netbeans.api.java.source.TreePathHandle;
65
import org.netbeans.api.java.source.TreePathHandle;
Lines 170-176 Link Here
170
                        TreePath bodyPath = new TreePath(methodPath, methodTree.getBody());
171
                        TreePath bodyPath = new TreePath(methodPath, methodTree.getBody());
171
                        scope = info.getTrees().getScope(bodyPath);
172
                        scope = info.getTrees().getScope(bodyPath);
172
                        
173
                        
173
                        final String parameterName = JavaPluginUtils.makeNameUnique(info, scope, name);
174
                        CodeStyle cs;
175
                        Document doc = info.getDocument();
176
                        if(doc != null) {
177
                            cs = CodeStyle.getDefault(doc);
178
                        } else {
179
                            cs = CodeStyle.getDefault(info.getFileObject());
180
                        }
181
                        final String parameterName = JavaPluginUtils.makeNameUnique(info, scope, name, cs.getParameterNamePrefix(), cs.getParameterNameSuffix());
174
                        
182
                        
175
                        SwingUtilities.invokeLater(new Runnable() {
183
                        SwingUtilities.invokeLater(new Runnable() {
176
                            @Override
184
                            @Override
(-)a/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/EncapsulateFieldsTest.java (-4 / +8 lines)
Lines 49-62 Link Here
49
import javax.lang.model.element.Modifier;
49
import javax.lang.model.element.Modifier;
50
import javax.lang.model.element.TypeElement;
50
import javax.lang.model.element.TypeElement;
51
import javax.lang.model.element.VariableElement;
51
import javax.lang.model.element.VariableElement;
52
import javax.lang.model.type.TypeKind;
52
import javax.lang.model.util.ElementFilter;
53
import javax.lang.model.util.ElementFilter;
54
import org.netbeans.api.java.source.CodeStyle;
55
import org.netbeans.api.java.source.CodeStyleUtils;
53
import org.netbeans.api.java.source.CompilationController;
56
import org.netbeans.api.java.source.CompilationController;
54
import org.netbeans.api.java.source.JavaSource;
57
import org.netbeans.api.java.source.JavaSource;
55
import org.netbeans.api.java.source.Task;
58
import org.netbeans.api.java.source.Task;
56
import org.netbeans.api.java.source.TreePathHandle;
59
import org.netbeans.api.java.source.TreePathHandle;
60
import org.netbeans.modules.java.source.save.DiffContext;
57
import org.netbeans.modules.refactoring.api.Problem;
61
import org.netbeans.modules.refactoring.api.Problem;
58
import org.netbeans.modules.refactoring.api.RefactoringSession;
62
import org.netbeans.modules.refactoring.api.RefactoringSession;
59
import org.netbeans.modules.refactoring.java.plugins.EncapsulateFieldRefactoringPlugin;
60
import org.netbeans.modules.refactoring.java.ui.EncapsulateFieldsRefactoring;
63
import org.netbeans.modules.refactoring.java.ui.EncapsulateFieldsRefactoring;
61
import org.openide.filesystems.FileObject;
64
import org.openide.filesystems.FileObject;
62
65
Lines 511-517 Link Here
511
            public void run(CompilationController info) throws Exception {
514
            public void run(CompilationController info) throws Exception {
512
                info.toPhase(JavaSource.Phase.RESOLVED);
515
                info.toPhase(JavaSource.Phase.RESOLVED);
513
                CompilationUnitTree cut = info.getCompilationUnit();
516
                CompilationUnitTree cut = info.getCompilationUnit();
514
517
                CodeStyle cs = DiffContext.getCodeStyle(info);
515
                final ClassTree classTree = (ClassTree) cut.getTypeDecls().get(0);
518
                final ClassTree classTree = (ClassTree) cut.getTypeDecls().get(0);
516
                final TreePath classPath = info.getTrees().getPath(cut, classTree);
519
                final TreePath classPath = info.getTrees().getPath(cut, classTree);
517
                TypeElement classEl = (TypeElement) info.getTrees().getElement(classPath);
520
                TypeElement classEl = (TypeElement) info.getTrees().getElement(classPath);
Lines 520-527 Link Here
520
                LinkedList<EncapsulateFieldsRefactoring.EncapsulateFieldInfo> fields = new LinkedList<EncapsulateFieldsRefactoring.EncapsulateFieldInfo>();
523
                LinkedList<EncapsulateFieldsRefactoring.EncapsulateFieldInfo> fields = new LinkedList<EncapsulateFieldsRefactoring.EncapsulateFieldInfo>();
521
                for (int p : position) {
524
                for (int p : position) {
522
                    VariableElement field = fieldsIn.get(p);
525
                    VariableElement field = fieldsIn.get(p);
523
                    String getName = EncapsulateFieldRefactoringPlugin.computeGetterName(field);
526
                    boolean staticMod = field.getModifiers().contains(Modifier.STATIC);
524
                    String setName = EncapsulateFieldRefactoringPlugin.computeSetterName(field);
527
                    String getName = CodeStyleUtils.computeGetterName(field.getSimpleName(), field.asType().getKind() == TypeKind.BOOLEAN, staticMod, cs);
528
                    String setName = CodeStyleUtils.computeSetterName(field.getSimpleName(), staticMod, cs);
525
                    EncapsulateFieldsRefactoring.EncapsulateFieldInfo encInfo = new EncapsulateFieldsRefactoring.EncapsulateFieldInfo(TreePathHandle.create(field, info), getName, setName);
529
                    EncapsulateFieldsRefactoring.EncapsulateFieldInfo encInfo = new EncapsulateFieldsRefactoring.EncapsulateFieldInfo(TreePathHandle.create(field, info), getName, setName);
526
                    fields.add(encInfo);
530
                    fields.add(encInfo);
527
                }
531
                }
(-)a/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/RefactoringTestBase.java (-1 / +1 lines)
Lines 131-137 Link Here
131
            assertNotNull(f);
131
            assertNotNull(f);
132
            assertNotNull(f.content);
132
            assertNotNull(f.content);
133
            assertNotNull("Cannot find " + f.filename + " in map " + content, fileContent);
133
            assertNotNull("Cannot find " + f.filename + " in map " + content, fileContent);
134
            assertEquals(getName() ,f.content.replaceAll("[ \t\n]+", " "), fileContent.replaceAll("[ \t\n]+", " "));
134
            assertEquals(getName() ,f.content.replaceAll("[ \t\r\n\n]+", " "), fileContent.replaceAll("[ \t\r\n\n]+", " "));
135
        }
135
        }
136
136
137
        assertTrue(content.toString(), content.isEmpty());
137
        assertTrue(content.toString(), content.isEmpty());

Return to bug 228870