Achal1607 commented on code in PR #8514:
URL: https://github.com/apache/netbeans/pull/8514#discussion_r2149338563


##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConfigValueCache.java:
##########
@@ -0,0 +1,296 @@
+/*
+ * 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.lsp.server.protocol;
+
+import com.google.gson.JsonElement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.BiConsumer;
+import org.eclipse.lsp4j.ConfigurationItem;
+import org.eclipse.lsp4j.ConfigurationParams;
+
+/**
+ * Cache for configuration values with support for hierarchical keys and change
+ * notifications
+ *
+ * @author atalati
+ */
+public class ConfigValueCache {
+
+    private final ConcurrentHashMap<String, Object> rootCache = new 
ConcurrentHashMap<>();
+    private static final String ROOT_KEY_VALUE = "";
+
+    public void registerListener(String section, BiConsumer<String, 
JsonElement> listener) {
+        ConfigData configData = getCachedConfigData(section);
+        if (configData != null) {
+            configData.setConsumer(listener);
+        } else {
+            setConfigInTree(section, new ConfigData(listener));
+        }
+    }
+
+    public void registerCache(String section) {
+        ConfigData configData = getCachedConfigData(section);
+        if (configData == null) {
+            setConfigInTree(section, new ConfigData());
+        }
+    }
+
+    public JsonElement getConfigValue(String section, String scope) {
+        ConfigData configData = getCachedConfigData(section);
+        if (configData == null) {
+            return null;
+        } else if (scope == null) {
+            return configData.getRootValue();
+        }
+        return configData.getScopedValue(scope);
+    }
+
+    public void updateCache(NbCodeLanguageClient client, String section, 
Object cacheValue, JsonElement tree) {
+        if (tree == null || cacheValue == null) {
+            return;
+        }
+
+        ConfigData rootData;
+        ConfigValueCache currentCache = null;
+
+        if (isConfigDataInstance(cacheValue)) {
+            rootData = (ConfigData) cacheValue;
+        } else if (isConfigValueInstance(cacheValue)) {
+            currentCache = (ConfigValueCache) cacheValue;
+            rootData = currentCache.getRootCacheValue();
+        } else {
+            return;
+        }
+
+        if (rootData != null) {
+            rootData.setRootValue(tree);
+            try {
+                BiConsumer<String, JsonElement> consumer = 
rootData.getConsumer();
+                if (consumer != null) {
+                    consumer.accept(section, tree);
+                }
+            } catch (RuntimeException e) {

Review Comment:
   Sorry, I missed this change, will push this as well.



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