junichi11 commented on code in PR #8227:
URL: https://github.com/apache/netbeans/pull/8227#discussion_r1950144252


##########
php/php.editor/src/org/netbeans/modules/php/editor/model/impl/PropertyHookSignatureItem.java:
##########
@@ -0,0 +1,298 @@
+/*
+ * 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.php.editor.model.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONAware;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.php.api.util.StringUtils;
+import org.netbeans.modules.php.editor.api.elements.ParameterElement;
+import org.netbeans.modules.php.editor.api.elements.PropertyHookElement;
+import org.netbeans.modules.php.editor.elements.ParameterElementImpl;
+import org.netbeans.modules.php.editor.model.PropertyHookScope;
+
+/**
+ * Represents a JSON format object for a property hook.
+ *
+ * Use "JSON simple". If we use "Jackson", problems(timeout,
+ * java.lang.NoClassDefFoundError) occurs in CI for Windows.
+ * <pre>
+ * e.g.
+ * {
+ *     "name":"set",
+ *     "start":3651,
+ *     "end":3690,
+ *     "mod":1,
+ *     "isRef":false,
+ *     "isAttr":false,
+ *     "hasBody":true,
+ *     "paramSig":"$value::0::1:1:0:0:0:0::"
+ * }
+ * </pre>
+ */
+public class PropertyHookSignatureItem implements JSONAware {
+
+    private static final Logger LOGGER = 
Logger.getLogger(PropertyHookSignatureItem.class.getName());
+    private static final String EMPTY_ARRAY = "[]"; // NOI18N
+
+    private String name;
+    private int start;
+    private int end;
+    private int mod;
+    private boolean isRef;
+    private boolean isAttr;
+    private boolean hasBody;
+    private String paramSig;
+
+    private PropertyHookSignatureItem(String name, int start, int end, int 
mod, boolean isAttr, boolean isRef, boolean hasBody, String paramSig) {
+        this.name = name;
+        this.start = start;
+        this.end = end;
+        this.mod = mod;
+        this.isAttr = isAttr;
+        this.isRef = isRef;
+        this.hasBody = hasBody;
+        this.paramSig = paramSig;
+    }
+
+    private PropertyHookSignatureItem(PropertyHookScope propertyHook) {
+        this(
+                propertyHook.getName(),
+                propertyHook.getOffsetRange().getStart(),
+                propertyHook.getOffsetRange().getEnd(),
+                propertyHook.getPhpModifiers().toFlags(),
+                propertyHook.isAttributed(),
+                propertyHook.isReference(),
+                propertyHook.hasBody(),
+                getParameterSignature(propertyHook.getParameters())
+        );
+    }
+
+    private PropertyHookSignatureItem(PropertyHookElement element) {
+        this(
+                element.getName(),
+                element.getOffsetRange().getStart(),
+                element.getOffsetRange().getEnd(),
+                element.getPhpModifiers().toFlags(),
+                element.isAttributed(),
+                element.isReference(),
+                element.hasBody(),
+                getParameterSignature(element.getParameters())
+        );
+    }
+
+    private static String getParameterSignature(List<? extends 
ParameterElement> params) {
+        StringBuilder sb = new StringBuilder();
+        for (ParameterElement param : params) {
+            ParameterElementImpl parameter = (ParameterElementImpl) param;
+            if (sb.length() > 0) {
+                sb.append(',');
+            }
+            sb.append(parameter.getSignature());
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Get a signature(JSON format) for PropetyHookScopes. (Serialize
+     * PropertyHookScopes.)
+     *
+     * e.g.
+     * 
`[{"name":"set","start":3651,"end":3690,"mod":1,"isRef":false,"isAttr":false,"hasBody":true,"paramSig":"$value::0::1:1:0:0:0:0::"}]`
+     *
+     * @param propertyHookScopes
+     * @return a signature for scopes
+     */
+    public static String getSignatureFromScopes(Collection<? extends 
PropertyHookScope> propertyHookScopes) {
+        final long start = (LOGGER.isLoggable(Level.FINE)) ? 
System.currentTimeMillis() : 0;
+        List<PropertyHookSignatureItem> signatureItems = 
getSignatureItemsFromScopes(propertyHookScopes);
+        String signature = EMPTY_ARRAY;
+        if (!signatureItems.isEmpty()) {
+            JSONArray items = new JSONArray();
+            items.addAll(signatureItems);
+            signature = items.toJSONString();
+            if (LOGGER.isLoggable(Level.FINE)) {
+                LOGGER.log(Level.FINE, "getSignatureFromScopes() took: {0} 
ms", (System.currentTimeMillis() - start)); // NOI18N

Review Comment:
   <details>
   <summary>Log</summary>
   
   ```
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 1 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   INFO [org.netbeans.ui.indexing]: Indexing finished, indexing took 19 ms.
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   INFO [org.netbeans.ui.indexing]: Indexing started, time from last indexing 
9,124 ms.
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 1 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   INFO [org.netbeans.ui.indexing]: Indexing finished, indexing took 36 ms.
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   INFO [org.netbeans.ui.indexing]: Indexing started, time from last indexing 
11,654 ms.
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
getSignatureFromScopes() took: 0 ms
   INFO [org.netbeans.ui.indexing]: Indexing finished, indexing took 14 ms.
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 1 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: 
fromSignature() took: 0 ms
   ```
   </details>
   
   Example:
   ```php
   
   <?php
   interface InterfaceA {
       public string $a1 {
           get;
       }
       public int $a2 {
           set;
       }
       public $b3 {
           get;
           set;
       }
   }
   
   interface InterfaceB extends InterfaceA {
       public string $b1 {
           get;
       }
       public int $b2 {
           set;
       }
       public $b3 {
           get;
           set;
       }
   }
   interface InterfaceX {
       public string $x1 {
           get;
       }
       public int $x2 {
           set;
       }
       public $x3 {
           get;
           set;
       }
   }
   
   interface InterfaceY extends InterfaceB {
       public string $y1 {
           get;
       }
       public int $y2 {
           set;
       }
       public $y3 {
           get;
           set;
       }
   }
   
   interface InterfaceZ extends InterfaceX, InterfaceY {
       public string $z1 {
           get;
       }
       final public int $z2 {
           set;
       }
       public $z3 {
           get;
           set;
       }
   }
   
   ```
   



-- 
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