kezhuw commented on code in PR #2206:
URL: https://github.com/apache/zookeeper/pull/2206#discussion_r1847720246


##########
zookeeper-jute/src/main/java/org/apache/jute/compiler/JCommentGenerator.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.apache.jute.compiler;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.Optional;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import org.apache.jute.compiler.generated.Token;
+
+public class JCommentGenerator {
+
+    /**
+     * {fieldCommentsBeginLineNumber : {fieldCommentsBeginColumn : 
fieldCommentsToken}}.
+     */
+    private final TreeMap<Integer, TreeMap<Integer, Token>> 
fieldCommentsTokenMap = new TreeMap<>();
+
+    /**
+     * {recordCommentsBeginLineNumber : {recordCommentsBeginColumn : 
recordCommentsToken}}.
+     */
+    private final TreeMap<Integer, TreeMap<Integer, Token>> 
recordCommentsTokenMap = new TreeMap<>();
+
+    private final TreeSet<RangeInfo> jFieldTreeSet = new TreeSet<>();
+
+    private final TreeSet<RangeInfo> jRecordTreeSet = new TreeSet<>();
+
+    public void addJRecord(JRecord jRecord) {
+        jRecordTreeSet.add(jRecord);
+    }
+
+    public void addJField(JField jField) {
+        jFieldTreeSet.add(jField);
+    }
+
+    public void putFieldSpecialToken(Token fieldToken) {
+        putSpecialToken(fieldToken, fieldCommentsTokenMap);
+    }
+
+    public void putRecordSpecialToken(Token recordToken) {
+        putSpecialToken(recordToken, recordCommentsTokenMap);
+    }
+
+    private static void putSpecialToken(Token classToken, TreeMap<Integer, 
TreeMap<Integer, Token>> commentsTokenMap) {
+        if (classToken == null || classToken.specialToken == null || 
commentsTokenMap == null) {
+            return;
+        }
+
+        Token tmp = classToken;
+        while ((tmp = tmp.specialToken) != null && tmp.image != null) {
+            commentsTokenMap.computeIfAbsent(tmp.beginLine, key -> new 
TreeMap<>())
+                    .putIfAbsent(tmp.beginColumn, tmp);
+        }
+    }
+
+    public List<String> getRecordCommentsList(JRecord jRecord) {
+        return getCommentsList(jRecord, jRecordTreeSet, 
recordCommentsTokenMap);
+    }
+
+    public List<String> getFieldCommentsList(JField jField) {
+        return getCommentsList(jField, jFieldTreeSet, fieldCommentsTokenMap);
+    }
+
+    private static List<String> getCommentsList(RangeInfo rangeInfo,

Review Comment:
   I expect this should be much clear. Given that we support only comments in 
three places:
   1. Comments before `class` for record types.
   2. Comments before fields.
   3. Line ending comments for fields.
   
   For the first, we could extract comments from `Token::specialToken`. For the 
second, similar to the first, but we have to drop comments(could be in either 
`//` or `/* */` form) belong to previous field. For the third, additional 
lookup is required, also drop comments belong to next field.



##########
zookeeper-jute/src/main/java/org/apache/jute/compiler/JCommentGenerator.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.apache.jute.compiler;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.Optional;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import org.apache.jute.compiler.generated.Token;
+
+public class JCommentGenerator {
+
+    /**
+     * {fieldCommentsBeginLineNumber : {fieldCommentsBeginColumn : 
fieldCommentsToken}}.
+     */
+    private final TreeMap<Integer, TreeMap<Integer, Token>> 
fieldCommentsTokenMap = new TreeMap<>();
+
+    /**
+     * {recordCommentsBeginLineNumber : {recordCommentsBeginColumn : 
recordCommentsToken}}.
+     */
+    private final TreeMap<Integer, TreeMap<Integer, Token>> 
recordCommentsTokenMap = new TreeMap<>();
+
+    private final TreeSet<RangeInfo> jFieldTreeSet = new TreeSet<>();
+
+    private final TreeSet<RangeInfo> jRecordTreeSet = new TreeSet<>();
+
+    public void addJRecord(JRecord jRecord) {
+        jRecordTreeSet.add(jRecord);
+    }
+
+    public void addJField(JField jField) {
+        jFieldTreeSet.add(jField);

Review Comment:
   `extends RangeInfo` is aggressive. `addCommentRange(JXyz jXyz, RangeInfo 
rangeInfo)` should be sufficient.



-- 
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...@zookeeper.apache.org

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

Reply via email to