From 0443410b66f3f4b7be74fcd4d03bd41f68abbbe8 Mon Sep 17 00:00:00 2001 From: markiewb Date: Sun, 18 Jan 2015 18:03:18 +0100 Subject: [PATCH] issue #16: Make the hyperlinking faster / use less IO - set cache to 10s and use it also for opening (still need to refactor the caching aspect into a separate class, but this will be handled in #17) --- .../ResourceHyperlinkProvider.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/markiewb/netbeans/plugins/resourcehyperlink/ResourceHyperlinkProvider.java b/src/main/java/de/markiewb/netbeans/plugins/resourcehyperlink/ResourceHyperlinkProvider.java index 312241a..c404904 100644 --- a/src/main/java/de/markiewb/netbeans/plugins/resourcehyperlink/ResourceHyperlinkProvider.java +++ b/src/main/java/de/markiewb/netbeans/plugins/resourcehyperlink/ResourceHyperlinkProvider.java @@ -96,8 +96,8 @@ public class ResourceHyperlinkProvider implements HyperlinkProviderExt { public static final String MAVEN_TYPE_OTHER = "Resources"; //NOI18N public static final String MAVEN_TYPE_TEST_OTHER = "TestResources"; //NOI18N public static final String MAVEN_TYPE_GEN_SOURCES = "GeneratedSources"; //NOI18N - public static Cache cache = new Cache(); - private static final int EXPIRE_CACHE_IN_SECONDS = 2; + public static final Cache cache = new Cache(); + private static final int EXPIRE_CACHE_IN_SECONDS = 10; public static void openInEditor(FileObject fileToOpen) { DataObject fileDO; @@ -363,7 +363,12 @@ private void updateCacheIfNecessary(Document doc, int offset) { @Override public void performClickAction(Document doc, int position, HyperlinkType type) { - ResultTO matches = findResources(doc, position); + updateCacheIfNecessary(doc, position); + if (null == cache.matches) { + return; + } + + ResultTO matches = cache.matches; if (matches.isValid()) { Collection foundMatches = matches.foundFiles; final Project project = FileOwnerQuery.getOwner(NbEditorUtilities.getFileObject(doc)); @@ -440,6 +445,9 @@ private Collection findByClassName(FileObject fo, String fqnClassNam ClassPath bootCp = ClassPath.getClassPath(fo, ClassPath.BOOT); ClassPath compileCp = ClassPath.getClassPath(fo, ClassPath.COMPILE); ClassPath sourcePath = ClassPath.getClassPath(fo, ClassPath.SOURCE); + if (null == bootCp || null == compileCp || null == sourcePath) { + return files; + } final ClasspathInfo info = ClasspathInfo.create(bootCp, compileCp, sourcePath); int lastIndexOfDot = fqnClassName.lastIndexOf("."); String simpleClassName;