jlahoda commented on a change in pull request #2324:
URL: https://github.com/apache/netbeans/pull/2324#discussion_r489178417
##########
File path:
java/java.sourceui/src/org/netbeans/modules/java/source/ui/JavaSymbolProvider.java
##########
@@ -117,145 +119,187 @@ public void computeSymbolNames(final Context context,
final Result result) {
final Cache cache = scanInProgress ?
Cache.create(textToSearch, st) :
null;
- String prefix = null;
- final int dotIndex = textToSearch.lastIndexOf('.'); //NOI18N
- if (dotIndex > 0 && dotIndex != textToSearch.length()-1) {
- prefix = textToSearch.substring(0, dotIndex);
- textToSearch = textToSearch.substring(dotIndex+1);
- }
- final String textToHighLight = textToSearch;
- ClassIndex.NameKind _kind;
- boolean _caseSensitive;
- switch (st) {
- case PREFIX:
- _kind = ClassIndex.NameKind.PREFIX;
- _caseSensitive = true;
- break;
- case REGEXP:
- _kind = ClassIndex.NameKind.REGEXP;
- textToSearch = NameMatcherFactory.wildcardsToRegexp(
- removeNonJavaChars(textToSearch),
- true);
- _caseSensitive = true;
- break;
- case CAMEL_CASE:
- _kind = ClassIndex.NameKind.CAMEL_CASE;
- _caseSensitive = true;
- break;
- case CASE_INSENSITIVE_CAMEL_CASE:
- _kind = ClassIndex.NameKind.CAMEL_CASE_INSENSITIVE;
- _caseSensitive = false;
- break;
- case EXACT_NAME:
- _kind = ClassIndex.NameKind.SIMPLE_NAME;
- _caseSensitive = true;
- break;
- case CASE_INSENSITIVE_PREFIX:
- _kind = ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
- _caseSensitive = false;
- break;
- case CASE_INSENSITIVE_EXACT_NAME:
- _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
- _caseSensitive = false;
- break;
- case CASE_INSENSITIVE_REGEXP:
- _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
- textToSearch = NameMatcherFactory.wildcardsToRegexp(
- removeNonJavaChars(textToSearch),
- true);
- _caseSensitive = false;
- break;
- default:
- throw new IllegalArgumentException();
- }
- final String ident = textToSearch;
- final ClassIndex.NameKind kind = _kind;
- final boolean caseSensitive = _caseSensitive;
- final Pair<NameMatcher,Boolean> restriction;
- if (prefix != null) {
- restriction = compileName(prefix,caseSensitive);
- result.setHighlightText(textToHighLight);
- } else {
- restriction = null;
- }
- try {
- final ClassIndexManager manager =
ClassIndexManager.getDefault();
-
- Collection<FileObject> roots = QuerySupport.findRoots(
- (Project)null,
- Collections.singleton(ClassPath.SOURCE),
- Collections.<String>emptySet(),
- Collections.<String>emptySet());
-
- final Set<URL> rootUrls = new HashSet<>();
- for(FileObject root : roots) {
- if (canceled) {
- return;
+ doComputeSymbols(st, textToSearch, new ResultHandler() {
+ private FileObject root;
+ private ProjectInformation projectInfo;
+ private ClassIndexImpl ci;
+ @Override
+ public void setHighlightText(String text) {
+ result.setHighlightText(text);
+ }
+
+ @Override
+ public void runRoot(FileObject root, ClassIndexImpl ci, Exec
exec) throws IOException, InterruptedException {
+ try {
+ Project project = FileOwnerQuery.getOwner(root);
+
+ this.root = root;
+ this.projectInfo = project == null ?
+ null :
+
project.getLookup().lookup(ProjectInformation.class); //Intentionally does
not use ProjectUtils.getInformation() it does project icon annotation which is
expensive
+ this.ci = ci;
+ exec.run();
+ } finally {
+ this.root = null;
+ this.projectInfo = null;
+ this.ci = null;
}
- rootUrls.add(root.toURL());
}
- if (LOGGER.isLoggable(Level.FINE)) {
- LOGGER.log(Level.FINE, "Querying following roots:");
//NOI18N
- for (URL url : rootUrls) {
- LOGGER.log(Level.FINE, " {0}", url); //NOI18N
+ @Override
+ public void handleResult(ElementHandle<TypeElement> owner,
String ident, boolean caseSensitive) {
+ final AsyncJavaSymbolDescriptor d = new
AsyncJavaSymbolDescriptor(
+ projectInfo,
+ root,
+ ci,
+ owner,
+ ident,
+ caseSensitive);
+ result.addResult(d);
+ if (cache != null) {
+ cache.offer(d);
}
- LOGGER.log(Level.FINE, "-------------------------");
//NOI18N
}
- //Perform all queries in single op
- IndexManager.priorityAccess(new IndexManager.Action<Void>() {
- @Override
- public Void run() throws IOException, InterruptedException
{
- for (URL url : rootUrls) {
- if (canceled) {
- return null;
- }
- final FileObject root =
URLMapper.findFileObject(url);
- if (root == null) {
- continue;
- }
-
- final Project project =
FileOwnerQuery.getOwner(root);
- final ProjectInformation projectInfo = project ==
null ?
- null :
-
project.getLookup().lookup(ProjectInformation.class); //Intentionally does
not use ProjectUtils.getInformation() it does project icon annotation which is
expensive
- final ClassIndexImpl impl =
manager.getUsagesQuery(root.toURL(), true);
- if (impl != null) {
+ }, true, canceled);
+ } finally {
+ clearCancel();
+ }
+ }
+
+ public static void doComputeSymbols(SearchType st, String textToSearch,
ResultHandler handler, boolean async, AtomicBoolean canceled) {
+ String prefix = null;
+ final int dotIndex = textToSearch.lastIndexOf('.'); //NOI18N
+ if (dotIndex > 0 && dotIndex != textToSearch.length()-1) {
+ prefix = textToSearch.substring(0, dotIndex);
+ textToSearch = textToSearch.substring(dotIndex+1);
+ }
+ final String textToHighLight = textToSearch;
+ ClassIndex.NameKind _kind;
+ boolean _caseSensitive;
+ switch (st) {
+ case PREFIX:
+ _kind = ClassIndex.NameKind.PREFIX;
+ _caseSensitive = true;
+ break;
+ case REGEXP:
+ _kind = ClassIndex.NameKind.REGEXP;
+ textToSearch = NameMatcherFactory.wildcardsToRegexp(
+ removeNonJavaChars(textToSearch),
+ true);
+ _caseSensitive = true;
+ break;
+ case CAMEL_CASE:
+ _kind = ClassIndex.NameKind.CAMEL_CASE;
+ _caseSensitive = true;
+ break;
+ case CASE_INSENSITIVE_CAMEL_CASE:
+ _kind = ClassIndex.NameKind.CAMEL_CASE_INSENSITIVE;
+ _caseSensitive = false;
+ break;
+ case EXACT_NAME:
+ _kind = ClassIndex.NameKind.SIMPLE_NAME;
+ _caseSensitive = true;
+ break;
+ case CASE_INSENSITIVE_PREFIX:
+ _kind = ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
+ _caseSensitive = false;
+ break;
+ case CASE_INSENSITIVE_EXACT_NAME:
+ _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
+ _caseSensitive = false;
+ break;
+ case CASE_INSENSITIVE_REGEXP:
+ _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
+ textToSearch = NameMatcherFactory.wildcardsToRegexp(
+ removeNonJavaChars(textToSearch),
+ true);
+ _caseSensitive = false;
+ break;
+ default:
+ throw new IllegalArgumentException();
+ }
+ final String ident = textToSearch;
+ final ClassIndex.NameKind kind = _kind;
+ final boolean caseSensitive = _caseSensitive;
+ final Pair<NameMatcher,Boolean> restriction;
+ if (prefix != null) {
+ restriction = compileName(prefix,caseSensitive);
+ handler.setHighlightText(textToHighLight);
+ } else {
+ restriction = null;
+ }
+ try {
+ final ClassIndexManager manager = ClassIndexManager.getDefault();
+
+ Collection<FileObject> roots = QuerySupport.findRoots(
+ (Project)null,
+ Collections.singleton(ClassPath.SOURCE),
+ Collections.<String>emptySet(),
+ Collections.<String>emptySet());
+
+ final Set<URL> rootUrls = new HashSet<>();
+ for(FileObject root : roots) {
+ if (canceled.get()) {
+ return;
+ }
+ rootUrls.add(root.toURL());
+ }
+
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.log(Level.FINE, "Querying following roots:"); //NOI18N
+ for (URL url : rootUrls) {
+ LOGGER.log(Level.FINE, " {0}", url); //NOI18N
+ }
+ LOGGER.log(Level.FINE, "-------------------------"); //NOI18N
+ }
+ //Perform all queries in single op
+ IndexManager.priorityAccess(new IndexManager.Action<Void>() {
Review comment:
It could, but the body is fairly long. Seems the anonymous class is a
better fit here.
----------------------------------------------------------------
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.
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