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


##########
java/java.hints/src/org/netbeans/modules/java/hints/OrganizeMembers.java:
##########
@@ -122,49 +122,44 @@ private static void doOrganizeMembers(WorkingCopy copy, 
TreePath path) {
         ClassTree clazz = (ClassTree) path.getLeaf();
         clazz = gu.importComments(clazz, copy.getCompilationUnit());
         TreeMaker maker = copy.getTreeMaker();
+
         ClassTree nue = maker.Class(clazz.getModifiers(), 
clazz.getSimpleName(), clazz.getTypeParameters(), clazz.getExtendsClause(), 
clazz.getImplementsClause(), clazz.getPermitsClause(), 
Collections.<Tree>emptyList());
-        List<Tree> members = new ArrayList<>(clazz.getMembers().size());
-        Map<Tree, Tree> memberMap = new HashMap<>(clazz.getMembers().size());
+        List<Tree> members = new ArrayList<>();
+        Map<Tree, Tree> memberMap = new HashMap<>();
         
-        List<Tree> enumValues = new ArrayList<>();
+        List<Tree> fixedMembers = new ArrayList<>();
         for (Tree tree : clazz.getMembers()) {
-            if (copy.getTreeUtilities().isSynthetic(new TreePath(path, tree))) 
{
+            // isSynthetic does not consider record components to be synthetic
+            if (copy.getTreeUtilities().isSynthetic(new TreePath(path, tree))
+                    && !(tree.getKind() == Kind.VARIABLE && 
copy.getTreeUtilities().isRecordComponent((VariableTree)tree))) {
                 continue;
             }

Review Comment:
   thought this is lower risk than updating `isSynthetic()` although it 
probably should be updated at some point.
   
   inserting
   ```java
               if (path.getLeaf().getKind() == Kind.VARIABLE &&
                   path.getParentPath() != null &&
                   path.getParentPath().getLeaf().getKind() == Kind.RECORD) {
                   Set<Modifier> mods = ((VariableTree) 
path.getLeaf()).getModifiers().getFlags();
                   if (!mods.contains(Modifier.STATIC)) {
                       return true; // all non static record fields are 
synthetic
                   }
               }
   ```
   at 
https://github.com/apache/netbeans/blob/e38f61876b02c5f47b0a4b019426812e54c2689f/java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java#L212
 would work



##########
java/java.hints/test/unit/src/org/netbeans/modules/java/hints/OrganizeMembersTest.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.hints;
+
+import java.util.prefs.Preferences;
+import org.netbeans.api.editor.mimelookup.MimeLookup;
+import org.netbeans.junit.NbTestCase;
+import org.netbeans.modules.editor.java.JavaKit;
+import org.netbeans.modules.java.hints.test.api.HintTest;
+import org.netbeans.modules.java.ui.FmtOptions;
+import org.openide.util.NbBundle;
+
+/**
+ * @author mbien
+ */
+public class OrganizeMembersTest extends NbTestCase {
+    
+    public OrganizeMembersTest(String name) {
+        super(name);
+    }
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        HintTest.create(); // initializes lookup (stolen from bugs.TinyTest)
+        MimeLookup.getLookup(JavaKit.JAVA_MIME_TYPE)
+                  .lookup(Preferences.class)
+                  .putBoolean(FmtOptions.sortMembersInGroups, true);
+    }
+
+    @Override
+    protected boolean runInEQ() {
+        // without it, hint markers are sometimes not found
+        return true;
+    }

Review Comment:
   don't know why this is needed. `OrganizeMembers` invokes 
`runModificationTask` which calls `copy.rewrite()` at some point. 
   
   `result.getDifferences(source.getFileObject())` is sometimes null if not on 
EDT.



-- 
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: notifications-unsubscr...@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

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

Reply via email to