You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/01/10 15:35:09 UTC

[GitHub] geertjanw closed pull request #346: add aditional options to the Replace Constructor with Builder window

geertjanw closed pull request #346: add aditional options to the Replace Constructor with Builder window
URL: https://github.com/apache/incubator-netbeans/pull/346
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/api/ReplaceConstructorWithBuilderRefactoring.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/api/ReplaceConstructorWithBuilderRefactoring.java
index 98fe8684d..29f7239e3 100644
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/api/ReplaceConstructorWithBuilderRefactoring.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/api/ReplaceConstructorWithBuilderRefactoring.java
@@ -49,6 +49,7 @@
 
     
     private String builderName;
+    private String buildMethodName;
     private List<Setter> setters;
 
     /**
@@ -67,6 +68,14 @@ public ReplaceConstructorWithBuilderRefactoring(@NonNull TreePathHandle construc
         return builderName;
     }
 
+    /**
+     * Getter for build method name
+     * @return name of build method
+     */
+    public @NonNull String getBuildMethodName() {
+        return buildMethodName;
+    }
+
     /**
      * 
      * @param builderName 
@@ -74,6 +83,14 @@ public ReplaceConstructorWithBuilderRefactoring(@NonNull TreePathHandle construc
     public void setBuilderName(@NonNull String builderName) {
         this.builderName = builderName;
     }
+    
+    /**
+     * 
+     * @param buildMethodName 
+     */
+    public void setBuildMethodName(@NonNull String buildMethodName) {
+        this.buildMethodName = buildMethodName;
+    }    
 
     /**
      * Getter for list of setters
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/Bundle.properties b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/Bundle.properties
index 58ecde224..ec59b7ec9 100644
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/Bundle.properties
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/Bundle.properties
@@ -259,5 +259,6 @@ ERR_UpperCaseWarning=The first letter of Java type should be in upper case.
 TAG_Deprecated=@deprecated Moved to '{'@link {0}'}'
 
 ERR_NoFactory=No factory method name specified.
+ERR_NoBuildMethod=No build method name specified.
 ERR_NotIdentifier={0} is not an identifier.
 ERR_FileExists=File {0} already exists.
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/ReplaceConstructorWithBuilderPlugin.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/ReplaceConstructorWithBuilderPlugin.java
index c25d0fe14..e76f5bbb5 100644
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/ReplaceConstructorWithBuilderPlugin.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/ReplaceConstructorWithBuilderPlugin.java
@@ -62,7 +62,7 @@
     private final ReplaceConstructorWithBuilderRefactoring refactoring;
     
     private final AtomicBoolean cancel = new AtomicBoolean();
-    private TreePathHandle treePathHandle;
+    private final TreePathHandle treePathHandle;
 
     public ReplaceConstructorWithBuilderPlugin(ReplaceConstructorWithBuilderRefactoring refactoring) {
         this.refactoring = refactoring;
@@ -112,12 +112,19 @@ protected Problem checkParameters(CompilationController javac) throws IOExceptio
     @Override
     public Problem fastCheckParameters() {
         String builderName = refactoring.getBuilderName();
+        String buildMethodName = refactoring.getBuildMethodName();
         if (builderName == null || builderName.length() == 0) {
             return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NoFactory"));
         }
         if (!SourceVersion.isName(builderName)) {
             return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NotIdentifier", builderName));
         }
+        if (buildMethodName == null || buildMethodName.isEmpty()) {
+            return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NoBuildMethod"));
+        }
+        if (!SourceVersion.isIdentifier(buildMethodName)) {
+            return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NotIdentifier", buildMethodName));
+        }
         final TreePathHandle constr = treePathHandle;
         ClassPath classPath = ClassPath.getClassPath(constr.getFileObject(), ClassPath.SOURCE);
         String name = refactoring.getBuilderName().replace(".", "/") + ".java";
@@ -140,6 +147,7 @@ public final Problem prepare(RefactoringElementsBag refactoringElements) {
         final TreePathHandle constr = refactoring.getRefactoringSource().lookup(TreePathHandle.class);
         final String[] ruleCode = new String[1];
         final String[] parentSimpleName = new String[1];
+        String buildMethodName = refactoring.getBuildMethodName();
 
         try {
             ModificationResult mod = JavaSource.forFileObject(constr.getFileObject()).runModificationTask(new Task<WorkingCopy>() {
@@ -284,7 +292,7 @@ public void run(WorkingCopy workingCopy) throws Exception {
 
                     members.add(make.Method(
                             make.Modifiers(EnumSet.of(Modifier.PUBLIC)),
-                            "create" + parent.getSimpleName(), //NOI18N
+                            buildMethodName, //NOI18N
                             make.Type(parent.asType()),
                             Collections.<TypeParameterTree>emptyList(),
                             Collections.<VariableTree>emptyList(),
@@ -367,7 +375,7 @@ public void transform(WorkingCopy copy, Occurrence occurrence) {
 
                     MethodInvocationTree create = make.MethodInvocation(
                             Collections.<ExpressionTree>emptyList(),
-                            make.MemberSelect(expression, "create" + parentSimpleName[0]), //NOI18N
+                            make.MemberSelect(expression,buildMethodName), //NOI18N
                             Collections.<ExpressionTree>emptyList());
 
 
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/Bundle.properties b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/Bundle.properties
index a61b31c20..425ae8abe 100644
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/Bundle.properties
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/Bundle.properties
@@ -459,6 +459,8 @@ ReplaceConstructorName=Replace Constructor With Factory
 ReplaceConstructorDescription=Replace Constructor {0} with Factory Method {1}
 LBL_ReplaceConstructorWithBuilderAction=Replace Constructor with &Builder...
 ReplaceConstructorWithBuilder.jLabel1.text=&Builder Class Name:
+ReplaceConstructorWithBuilder.jLabel2.text=&Setter prefix:
+ReplaceConstructorWithBuilder.jLabel3.text=Build &Method Name:
 ReplaceConstructorWithBuilderName=Replace Constructor With Builder
 ReplaceConstructorWithBuilderDescription=Replace Constructor {0} with Builder {1}
 WhereUsedPanelMethod.searchOverloaded.text=Include overloaded methods
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderAction.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderAction.java
index fd96ce2b1..7f40d7103 100644
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderAction.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderAction.java
@@ -18,8 +18,6 @@
  */
 package org.netbeans.modules.refactoring.java.ui;
 
-import org.netbeans.modules.refactoring.java.ui.ContextAnalyzer;
-import org.netbeans.modules.refactoring.java.ui.JavaRefactoringGlobalAction;
 import org.openide.awt.ActionID;
 import org.openide.awt.ActionReference;
 import org.openide.awt.ActionReferences;
@@ -44,14 +42,17 @@ public ReplaceConstructorWithBuilderAction() {
         putValue("noIconInMenu", Boolean.TRUE); // NOI18N
     }
 
+    @Override
     public org.openide.util.HelpCtx getHelpCtx() {
         return HelpCtx.DEFAULT_HELP;
     }
 
+    @Override
     protected boolean asynchronous() {
         return false;
     }
 
+    @Override
     protected boolean enable(Lookup context) {
         return ContextAnalyzer.canRefactorSingle(context, true, false);
     }
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderPanel.form b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderPanel.form
index 5eb8d5a9d..10c7ee8ac 100644
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderPanel.form
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderPanel.form
@@ -37,30 +37,52 @@
   <Layout>
     <DimensionLayout dim="0">
       <Group type="103" groupAlignment="0" attributes="0">
-          <Group type="102" alignment="0" attributes="0">
+          <Component id="paramScrollPane" pref="561" max="32767" attributes="0"/>
+          <Group type="102" attributes="0">
+              <Component id="prefixLabel" min="-2" max="-2" attributes="0"/>
               <EmptySpace max="-2" attributes="0"/>
-              <Component id="builderName" min="-2" max="-2" attributes="0"/>
+              <Component id="prefixField" min="-2" pref="176" max="-2" attributes="0"/>
+              <EmptySpace max="32767" attributes="0"/>
+          </Group>
+          <Group type="102" alignment="1" attributes="0">
+              <Group type="103" groupAlignment="0" max="-2" attributes="0">
+                  <Component id="buildMethodName" max="32767" attributes="0"/>
+                  <Component id="buildName" max="32767" attributes="0"/>
+              </Group>
               <EmptySpace max="-2" attributes="0"/>
-              <Component id="nameField" pref="233" max="32767" attributes="0"/>
+              <Group type="103" groupAlignment="0" attributes="0">
+                  <Component id="buildMethodNameField" max="32767" attributes="0"/>
+                  <Component id="nameField" max="32767" attributes="0"/>
+              </Group>
           </Group>
-          <Component id="paramScrollPane" pref="0" max="32767" attributes="0"/>
       </Group>
     </DimensionLayout>
     <DimensionLayout dim="1">
       <Group type="103" groupAlignment="0" attributes="0">
           <Group type="102" alignment="1" attributes="0">
-              <Component id="paramScrollPane" pref="162" max="32767" attributes="0"/>
+              <Group type="103" groupAlignment="3" attributes="0">
+                  <Component id="prefixLabel" alignment="3" min="-2" max="-2" attributes="0"/>
+                  <Component id="prefixField" alignment="3" min="-2" max="-2" attributes="0"/>
+              </Group>
+              <EmptySpace max="-2" attributes="0"/>
+              <Component id="paramScrollPane" min="-2" pref="154" max="-2" attributes="0"/>
+              <EmptySpace min="-2" pref="7" max="-2" attributes="0"/>
+              <Group type="103" groupAlignment="3" attributes="0">
+                  <Component id="buildMethodName" alignment="3" min="-2" max="-2" attributes="0"/>
+                  <Component id="buildMethodNameField" alignment="3" min="-2" max="-2" attributes="0"/>
+              </Group>
               <EmptySpace max="-2" attributes="0"/>
               <Group type="103" groupAlignment="3" attributes="0">
-                  <Component id="builderName" alignment="3" min="-2" max="-2" attributes="0"/>
+                  <Component id="buildName" alignment="3" min="-2" max="-2" attributes="0"/>
                   <Component id="nameField" alignment="3" min="-2" max="-2" attributes="0"/>
               </Group>
+              <EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
           </Group>
       </Group>
     </DimensionLayout>
   </Layout>
   <SubComponents>
-    <Component class="javax.swing.JLabel" name="builderName">
+    <Component class="javax.swing.JLabel" name="buildName">
       <Properties>
         <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
           <ResourceString bundle="org/netbeans/modules/java/hints/jackpot/refactoring/Bundle.properties" key="ReplaceConstructorWithBuilder.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
@@ -70,7 +92,7 @@
         <AuxValue name="generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
       </AuxValues>
     </Component>
-    <Component class="javax.swing.JTextField" name="nameField">
+    <Component class="javax.swing.JTextField" name="buildMethodNameField">
       <Properties>
         <Property name="columns" type="int" value="15"/>
       </Properties>
@@ -94,5 +116,35 @@
         </Component>
       </SubComponents>
     </Container>
+    <Component class="javax.swing.JLabel" name="prefixLabel">
+      <Properties>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="org/netbeans/modules/refactoring/java/ui/Bundle.properties" key="ReplaceConstructorWithBuilder.jLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+      <AuxValues>
+        <AuxValue name="generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
+      </AuxValues>
+    </Component>
+    <Component class="javax.swing.JTextField" name="prefixField">
+      <Properties>
+        <Property name="columns" type="int" value="15"/>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JLabel" name="buildMethodName">
+      <Properties>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="org/netbeans/modules/refactoring/java/ui/Bundle.properties" key="ReplaceConstructorWithBuilder.jLabel3.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+      <AuxValues>
+        <AuxValue name="generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
+      </AuxValues>
+    </Component>
+    <Component class="javax.swing.JTextField" name="nameField">
+      <Properties>
+        <Property name="columns" type="int" value="15"/>
+      </Properties>
+    </Component>
   </SubComponents>
 </Form>
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderPanel.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderPanel.java
index 3d0db3209..3e3022214 100644
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderPanel.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderPanel.java
@@ -25,9 +25,11 @@
 import javax.swing.JTable;
 import javax.swing.event.*;
 import javax.swing.table.DefaultTableModel;
+import javax.swing.text.BadLocationException;
 import org.netbeans.api.annotations.common.NonNull;
 import org.netbeans.modules.refactoring.java.api.ReplaceConstructorWithBuilderRefactoring;
 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
+import org.openide.util.Exceptions;
 import org.openide.util.NbBundle;
 
 /**
@@ -36,6 +38,7 @@
  */
 public class ReplaceConstructorWithBuilderPanel extends javax.swing.JPanel implements CustomRefactoringPanel {
 
+    private final static String DEFAULT_PREFIX = "set";
     private static final String[] columnNames = {
         getString("LBL_BuilderParameter"), // NOI18N
         getString("LBL_BuilderSetterName"), // NOI18N
@@ -48,13 +51,18 @@
     private static final Class[] columnTypes = new Class[]{
         String.class, String.class, String.class, Boolean.class
     };
-    private List<String> parameterTypes;
-    private List<Boolean> parameterTypeVars;
+    private final List<String> parameterTypes;
+    private final List<Boolean> parameterTypeVars;
+    private final List<String> parameterNames;
 
     public ReplaceConstructorWithBuilderPanel(final @NonNull ChangeListener parent, String initialFQN,
+            String initialBuildMethodName,
             List<String> paramaterNames, List<String> parameterTypes, List<Boolean> parameterTypeVars) {
         initComponents();
         this.parameterTypes = parameterTypes;
+        this.parameterNames = paramaterNames;
+        prefixField.setText(DEFAULT_PREFIX);
+        buildMethodNameField.setText(initialBuildMethodName);
         nameField.setText(initialFQN);
         nameField.setSelectionStart(0);
         nameField.setSelectionEnd(nameField.getText().length());
@@ -74,10 +82,25 @@ public void removeUpdate(DocumentEvent e) {
             public void changedUpdate(DocumentEvent e) {
             }
         });
+        buildMethodNameField.getDocument().addDocumentListener(new DocumentListener() {
+            @Override
+            public void insertUpdate(DocumentEvent e) {
+                parent.stateChanged(new ChangeEvent(ReplaceConstructorWithBuilderPanel.this));
+            }
+
+            @Override
+            public void removeUpdate(DocumentEvent e) {
+                parent.stateChanged(new ChangeEvent(ReplaceConstructorWithBuilderPanel.this));
+            }
+
+            @Override
+            public void changedUpdate(DocumentEvent e) {
+            }
+        });        
         DefaultTableModel model = (DefaultTableModel) paramTable.getModel();
         Iterator<String> typesIt = parameterTypes.iterator();
         for (String name : paramaterNames) {
-            model.addRow(new Object[]{typesIt.next() + " " + name, "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1), null, false}); //NOI18N
+            model.addRow(new Object[]{typesIt.next() + " " + name, DEFAULT_PREFIX + Character.toUpperCase(name.charAt(0)) + name.substring(1), null, false}); //NOI18N
         }
         model.addTableModelListener(new TableModelListener() {
             @Override
@@ -85,6 +108,31 @@ public void tableChanged(TableModelEvent e) {
                 parent.stateChanged(new ChangeEvent(ReplaceConstructorWithBuilderPanel.this));
             }
         });
+        prefixField.getDocument().addDocumentListener(new DocumentListener() {
+            @Override
+            public void insertUpdate(DocumentEvent de) {
+                updateSetters(de);
+            }
+
+            @Override
+            public void removeUpdate(DocumentEvent de) {
+                updateSetters(de);
+            }
+
+            @Override
+            public void changedUpdate(DocumentEvent de) {
+                updateSetters(de);
+            }
+
+            private void updateSetters(DocumentEvent de) {
+                try {
+                    String prefix = de.getDocument().getText(0, de.getDocument().getLength());
+                    updateSetterNames(prefix);
+                } catch (BadLocationException ex) {
+                    Exceptions.printStackTrace(ex);
+                }
+            }
+        });
         this.parameterTypeVars = parameterTypeVars;
     }
 
@@ -97,8 +145,8 @@ public void tableChanged(TableModelEvent e) {
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
     private void initComponents() {
 
-        builderName = new javax.swing.JLabel();
-        nameField = new javax.swing.JTextField();
+        buildName = new javax.swing.JLabel();
+        buildMethodNameField = new javax.swing.JTextField();
         paramScrollPane = new javax.swing.JScrollPane();
         paramTable = new JTable() {
 
@@ -110,10 +158,12 @@ public boolean isCellEditable(int row, int column) {
                 return super.isCellEditable(row, column);
             }
         };
+        prefixLabel = new javax.swing.JLabel();
+        prefixField = new javax.swing.JTextField();
+        buildMethodName = new javax.swing.JLabel();
+        nameField = new javax.swing.JTextField();
 
-        org.openide.awt.Mnemonics.setLocalizedText(builderName, org.openide.util.NbBundle.getMessage(ReplaceConstructorWithBuilderPanel.class, "ReplaceConstructorWithBuilder.jLabel1.text")); // NOI18N
-
-        nameField.setColumns(15);
+        org.openide.awt.Mnemonics.setLocalizedText(buildName, org.openide.util.NbBundle.getMessage(ReplaceConstructorWithBuilderPanel.class, "ReplaceConstructorWithBuilder.jLabel1.text")); // NOI18N
 
         paramTable.setModel(new javax.swing.table.DefaultTableModel(
             new Object[][]{}, columnNames) {
@@ -127,32 +177,57 @@ public boolean isCellEditable(int rowIndex, int columnIndex) {
         });
         paramScrollPane.setViewportView(paramTable);
 
+        org.openide.awt.Mnemonics.setLocalizedText(prefixLabel, org.openide.util.NbBundle.getMessage(ReplaceConstructorWithBuilderPanel.class, "ReplaceConstructorWithBuilder.jLabel2.text")); // NOI18N
+
+        org.openide.awt.Mnemonics.setLocalizedText(buildMethodName, org.openide.util.NbBundle.getMessage(ReplaceConstructorWithBuilderPanel.class, "ReplaceConstructorWithBuilder.jLabel3.text")); // NOI18N
+
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         this.setLayout(layout);
         layout.setHorizontalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addComponent(paramScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE)
             .addGroup(layout.createSequentialGroup()
-                .addContainerGap()
-                .addComponent(builderName)
+                .addComponent(prefixLabel)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-                .addComponent(nameField, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE))
-            .addComponent(paramScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
+                .addComponent(prefixField, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+                    .addComponent(buildMethodName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                    .addComponent(buildName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(buildMethodNameField)
+                    .addComponent(nameField)))
         );
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
-                .addComponent(paramScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                    .addComponent(prefixLabel)
+                    .addComponent(prefixField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(paramScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGap(7, 7, 7)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                    .addComponent(buildMethodName)
+                    .addComponent(buildMethodNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-                    .addComponent(builderName)
-                    .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
+                    .addComponent(buildName)
+                    .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addGap(3, 3, 3))
         );
     }// </editor-fold>//GEN-END:initComponents
     // Variables declaration - do not modify//GEN-BEGIN:variables
-    private javax.swing.JLabel builderName;
+    private javax.swing.JLabel buildMethodName;
+    private javax.swing.JTextField buildMethodNameField;
+    private javax.swing.JLabel buildName;
     private javax.swing.JTextField nameField;
     private javax.swing.JScrollPane paramScrollPane;
     private javax.swing.JTable paramTable;
+    private javax.swing.JTextField prefixField;
+    private javax.swing.JLabel prefixLabel;
     // End of variables declaration//GEN-END:variables
 
     @Override
@@ -162,6 +237,10 @@ public void initialize() {
     public String getBuilderName() {
         return nameField.getText();
     }
+    
+    public String getBuildMethodName() {
+        return buildMethodNameField.getText();
+    }
 
     @Override
     public boolean requestFocusInWindow() {
@@ -192,4 +271,18 @@ public Component getComponent() {
     private static String getString(String key) {
         return NbBundle.getMessage(ReplaceConstructorWithBuilderPanel.class, key);
     }
+    
+    private void updateSetterNames(String prefix) {
+        DefaultTableModel model = (DefaultTableModel) paramTable.getModel();
+        
+        for (int k = 0;k < parameterNames.size();k ++) {
+            if (prefix == null || prefix.isEmpty()) {
+                model.setValueAt(parameterNames.get(k),k,1);
+            } else {
+                model.setValueAt(prefix + Character.toUpperCase(parameterNames.get(k).charAt(0)) 
+                        + parameterNames.get(k).substring(1),k,1);
+            }
+        }
+        
+    }
 }
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderUI.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderUI.java
index 238579bd6..075a53715 100644
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderUI.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ReplaceConstructorWithBuilderUI.java
@@ -58,6 +58,7 @@
 
     private ReplaceConstructorWithBuilderRefactoring refactoring;
     private String builderFQN;
+    private String buildMethodName;
     private ReplaceConstructorWithBuilderPanel panel;
     private String name;
     private List <String> paramaterNames;
@@ -96,6 +97,7 @@ private ReplaceConstructorWithBuilderUI(TreePathHandle constructor, CompilationI
         } else {
             builderFQN = typeEl.getQualifiedName().toString();
         }
+        buildMethodName = "create" + typeEl.getSimpleName();
     }
 
     private ReplaceConstructorWithBuilderUI() {
@@ -119,7 +121,8 @@ public boolean isQuery() {
     @Override
     public CustomRefactoringPanel getPanel(final ChangeListener parent) {
         if (panel == null) {
-            panel = new ReplaceConstructorWithBuilderPanel(parent, builderFQN + "Builder", paramaterNames, parameterTypes, parameterTypeVars);
+            panel = new ReplaceConstructorWithBuilderPanel(parent, builderFQN + "Builder", buildMethodName,
+                    paramaterNames, parameterTypes, parameterTypeVars);
         }
         return panel;
     }
@@ -128,6 +131,7 @@ public CustomRefactoringPanel getPanel(final ChangeListener parent) {
     public Problem setParameters() {
         refactoring.setSetters(panel.getSetters());
         refactoring.setBuilderName(panel.getBuilderName());
+        refactoring.setBuildMethodName(panel.getBuildMethodName());
         return refactoring.checkParameters();
     }
 
@@ -135,6 +139,7 @@ public Problem setParameters() {
     public Problem checkParameters() {
         refactoring.setSetters(panel.getSetters());
         refactoring.setBuilderName(panel.getBuilderName());
+        refactoring.setBuildMethodName(panel.getBuildMethodName());
         return refactoring.fastCheckParameters();
     }
 
diff --git a/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/ReplaceConstructorWithBuilderTest.java b/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/ReplaceConstructorWithBuilderTest.java
index 2b3f41a5f..5b2754309 100644
--- a/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/ReplaceConstructorWithBuilderTest.java
+++ b/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/ReplaceConstructorWithBuilderTest.java
@@ -95,6 +95,20 @@ public void testReplaceWithBuilder() throws Exception {
                 new File("test/TestBuilder.java", "package test; public class TestBuilder { private int i; public TestBuilder() { } public TestBuilder setI(int i) { this.i = i; return this; } public Test createTest() { return new Test(i); } } "));
     }
     
+    
+    public void testReplaceWithBuilderBuildMethod() throws Exception {
+        writeFilesAndWaitForScan(src,
+                new File("test/Test.java", "package test;\n public class Test {\n public Test() {}\n private void t() {\n Test t = new Test();\n }\n }\n"),
+                new File("test/Use.java", "package test; public class Use { private void t(java.util.List<String> ll) { Test t = new Test(); } }"));
+
+        performTest2("test.TestBuilder", "build");
+
+        assertContent(src,
+                new File("test/Test.java", "package test;\n public class Test {\n public Test() {}\n private void t() {\n Test t = new TestBuilder().build();\n }\n }\n"),
+                new File("test/Use.java", "package test; public class Use { private void t(java.util.List<String> ll) { Test t = new TestBuilder().build(); } }"),
+                new File("test/TestBuilder.java", "package test; public class TestBuilder { public TestBuilder() { } public Test build() { return new Test(); } } "));
+    }      
+    
     public void testReplaceWithBuilderUndo() throws Exception {
         writeFilesAndWaitForScan(src,
                 new File("test/Test.java", "package test;\n public class Test {\n public Test(int i) {}\n private void t() {\n Test t = new Test(1);\n }\n }\n"),
@@ -162,7 +176,7 @@ public void test212135() throws Exception {
                 new File("test/Test.java", "package test; public class Test { public Test() { } }"),
                 new File("test/Use.java", "package test; public class Use { private void t(java.util.List<String> ll) { Test t = new Test(); } }"));
 
-        performTest2("test.TestBuilder");
+        performTest2("test.TestBuilder","createTest");
 
         assertContent(src,
                 new File("test/Test.java", "package test; public class Test { public Test() { } }"),
@@ -211,7 +225,7 @@ public void run(CompilationController parameter) throws Exception {
                 TreePath tp = TreePath.getPath(cut, var);
                 r[0] = new ReplaceConstructorWithBuilderRefactoring(TreePathHandle.create(tp, parameter));
                 r[0].setBuilderName(builderName);
-
+                r[0].setBuildMethodName("createTest");
                 r[0].setSetters(Collections.singletonList(setter));
             }
         }, true);
@@ -234,7 +248,7 @@ public void run(CompilationController parameter) throws Exception {
         //assertEquals(false, TaskCache.getDefault().isInError(src, true));
     }
     
-    private void performTest2(final String builderName) throws Exception {
+    private void performTest2(final String builderName,final String buildMethodName) throws Exception {
         final ReplaceConstructorWithBuilderRefactoring[] r = new ReplaceConstructorWithBuilderRefactoring[1];
         FileObject testFile = src.getFileObject("test/Test.java");
 
@@ -249,6 +263,7 @@ public void run(CompilationController parameter) throws Exception {
                 TreePath tp = TreePath.getPath(cut, var);
                 r[0] = new ReplaceConstructorWithBuilderRefactoring(TreePathHandle.create(tp, parameter));
                 r[0].setBuilderName(builderName);
+                r[0].setBuildMethodName(buildMethodName);
             }
         }, true);
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists