mbien commented on code in PR #7104:
URL: https://github.com/apache/netbeans/pull/7104#discussion_r1502968286


##########
java/maven.refactoring/src/org/netbeans/modules/maven/refactoring/MavenRefactoringPlugin.java:
##########
@@ -73,6 +93,46 @@ class MavenRefactoringPlugin implements RefactoringPlugin {
             }
             @Override public void cancel() {}
         };
+        
+        if (refactoring != null) {
+            ModelOperation<POMModel> operation = (final POMModel model) -> {
+                Properties pr = model.getProject().getProperties();
+                ElementHandle e = handle.getElementHandle();
+                if (e != null) {
+                    String oldName = e.getBinaryName();
+                    String newName = refactoring.getNewName();
+
+                    if (pr.getProperty(RUN_MAIN_CLASS) != null) {
+                        String oldProperty = pr.getProperty(RUN_MAIN_CLASS);
+                        if (oldProperty.equals(oldName)) {
+                            int lastIndex = oldName.lastIndexOf('.');
+                            String newPropertyValue = newName;
+                            if (lastIndex >= 0) {
+                                String packageName = oldName.substring(0, 
lastIndex + 1);
+                                newPropertyValue = packageName + 
newPropertyValue;
+                            }
+                            pr.setProperty(RUN_MAIN_CLASS, newPropertyValue);
+                        }
+                    }
+                }
+            };
+
+            try {
+                FileObject fo = handle.getFileObject();
+                Project p = FileOwnerQuery.getOwner(fo);
+                final FileObject pom = 
p.getProjectDirectory().getFileObject("pom.xml"); // NOI18N
+                pom.getFileSystem().runAtomicAction(() -> {
+                    List<ModelOperation<POMModel>> operations = new 
ArrayList<>();
+                    operations.add(operation);
+                    
org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(pom, 
operations);

Review Comment:
   a bit shorter:
   ```java
   performPOMModelOperations(pom, Arrays.asList(operation))
   ```
   



##########
java/maven.refactoring/src/org/netbeans/modules/maven/refactoring/MavenRefactoringPlugin.java:
##########
@@ -73,6 +93,46 @@ class MavenRefactoringPlugin implements RefactoringPlugin {
             }
             @Override public void cancel() {}
         };
+        
+        if (refactoring != null) {
+            ModelOperation<POMModel> operation = (final POMModel model) -> {

Review Comment:
   just a thought: if `operation` is renamed to `renameMainClassProp`, it would 
implicitly document what it does.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to