dbalek commented on code in PR #6123:
URL: https://github.com/apache/netbeans/pull/6123#discussion_r1243344207


##########
enterprise/micronaut/src/org/netbeans/modules/micronaut/symbol/MicronautSymbolSearcher.java:
##########
@@ -0,0 +1,259 @@
+/*
+ * 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.micronaut.symbol;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+import javax.swing.Icon;
+import org.netbeans.api.java.project.JavaProjectConstants;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectUtils;
+import org.netbeans.api.project.SourceGroup;
+import org.netbeans.modules.csl.api.IndexSearcher;
+import org.netbeans.modules.csl.api.Modifier;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.spi.GsfUtilities;
+import org.netbeans.modules.csl.spi.ParserResult;
+import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
+import org.netbeans.modules.parsing.spi.indexing.support.QuerySupport.Kind;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.filesystems.URLMapper;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author Dusan Balek
+ */
+@ServiceProvider(service=IndexSearcher.class)
+public class MicronautSymbolSearcher implements IndexSearcher {
+
+    @Override
+    public Set<? extends Descriptor> getTypes(Project project, String 
textForQuery, Kind searchType, Helper helper) {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public Set<? extends Descriptor> getSymbols(Project project, String 
textForQuery, Kind searchType, Helper helper) {
+        if (project == null || !textForQuery.startsWith("@")) {
+            return Collections.emptySet();
+        }
+        Set<Descriptor> symbols = new HashSet<>();
+        for (SourceGroup sg : 
ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA))
 {
+            try {
+                FileObject cacheRoot = 
getCacheRoot(sg.getRootFolder().toURL());
+                if (cacheRoot != null) {
+                    Enumeration<? extends FileObject> children = 
cacheRoot.getChildren(true);
+                    while (children.hasMoreElements()) {
+                        FileObject child = children.nextElement();
+                        if (child.hasExt("mn")) { //NOI18N
+                            loadSymbols(child, symbols);
+                        }
+                    }
+                }
+            } catch (IOException ex) {}
+        }
+        return symbols;
+    }
+
+    private static void loadSymbols(FileObject input, Set<Descriptor> symbols) 
{
+        try (BufferedReader br = new BufferedReader(new 
InputStreamReader(input.getInputStream(), StandardCharsets.UTF_8))) {
+            FileObject fo = null;
+            String line;
+            while ((line = br.readLine()) != null) {
+                if (line.startsWith("url: ")) { //NOI18N
+                    String url = line.substring(5);
+                    fo = URLMapper.findFileObject(URI.create(url).toURL());
+                    if (fo == null) {

Review Comment:
   No - index is stored in `*.mn` files created per java source file. In case 
the source file is removed, only symbols for that particular file are skipped.



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