[hg] main-silver: #231655 always manipulate token hierarchies un...

  • From: Milos Kleint < >
  • To: ,
  • Subject: [hg] main-silver: #231655 always manipulate token hierarchies un...
  • Date: Tue, 02 Jul 2013 11:55:08 -0700

changeset b9fe5f6da343 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/b9fe5f6da343
description:
        #231655 always manipulate token hierarchies under document lock

diffstat:

 
maven.grammar/src/org/netbeans/modules/maven/hyperlinks/HyperlinkProviderImpl.java
 |  119 ++++++++-
 1 files changed, 96 insertions(+), 23 deletions(-)

diffs (205 lines):

diff --git 
a/maven.grammar/src/org/netbeans/modules/maven/hyperlinks/HyperlinkProviderImpl.java
 
b/maven.grammar/src/org/netbeans/modules/maven/hyperlinks/HyperlinkProviderImpl.java
--- 
a/maven.grammar/src/org/netbeans/modules/maven/hyperlinks/HyperlinkProviderImpl.java
+++ 
b/maven.grammar/src/org/netbeans/modules/maven/hyperlinks/HyperlinkProviderImpl.java
@@ -93,7 +93,15 @@
     private static final Logger LOG = 
Logger.getLogger(HyperlinkProviderImpl.class.getName());
     
     @Override
-    public boolean isHyperlinkPoint(Document doc, int offset, HyperlinkType 
type) {
+    public boolean isHyperlinkPoint(final Document doc, final int offset, 
HyperlinkType type) {
+        final boolean[] isText = new boolean[1];
+        final int[] ftokenOff = new int[1];
+        final String[] ftext = new String[1];
+        doc.render(new Runnable() {
+
+            @Override
+            public void run() {
+                isText[0] = false;
         TokenHierarchy th = TokenHierarchy.get(doc);
         TokenSequence<XMLTokenId> xml = 
th.tokenSequence(XMLTokenId.language());
         xml.move(offset);
@@ -102,13 +110,22 @@
 
         // when it's not a value -> do nothing.
         if (token == null) {
-            return false;
+                   
+                    return;
         }
-        int tokenOff = xml.offset();        
         if (token.id() == XMLTokenId.TEXT) {
+                    isText[0] = true;
+                    ftokenOff[0] = xml.offset();
+                    ftext[0] = token.text().toString();
+                }
+            }
+        });
+           
+        if (isText[0]) {
             //we are in element text
             FileObject fo = getProjectDir(doc);
-            String text = token.text().toString();
+            String text = ftext[0];
+            int tokenOff = ftokenOff[0];
             if (fo != null && getPath(fo, text) != null) {
                 return true;
             }
@@ -137,21 +154,40 @@
     }
 
     @Override
-    public int[] getHyperlinkSpan(Document doc, int offset, HyperlinkType 
type) {
+    public int[] getHyperlinkSpan(final Document doc, final int offset, 
HyperlinkType type) {
+        final boolean[] isText = new boolean[1];
+        final int[] ftokenOff = new int[1];
+        final String[] ftext = new String[1];
+        
+        doc.render(new Runnable() {
+
+            @Override
+            public void run() {
+                isText[0] = false;
         TokenHierarchy th = TokenHierarchy.get(doc);
         TokenSequence<XMLTokenId> xml = 
th.tokenSequence(XMLTokenId.language());
         xml.move(offset);
         xml.moveNext();
         Token<XMLTokenId> token = xml.token();
+
         // when it's not a value -> do nothing.
         if (token == null) {
-            return null;
+                   
+                    return;
         }
-        int tokenOff = xml.offset();        
         if (token.id() == XMLTokenId.TEXT) {
+                    isText[0] = true;
+                    ftokenOff[0] = xml.offset();
+                    ftext[0] = token.text().toString();
+                }
+            }
+        });
+               
+        if (isText[0]) {
             //we are in element text
             FileObject fo = getProjectDir(doc);
-            String text = token.text().toString();
+            int tokenOff = ftokenOff[0];
+            String text = ftext[0];
             if (fo != null && getPath(fo, text) != null) {
                 return new int[] { tokenOff, tokenOff + text.length() };
             }
@@ -172,38 +208,57 @@
     }
 
     @Override
-    public void performClickAction(Document doc, int offset, HyperlinkType 
type) {
+    public void performClickAction(final Document doc, final int offset, 
HyperlinkType type) {
+        final boolean[] isText = new boolean[1];
+        final int[] ftokenOff = new int[1];
+        final String[] ftext = new String[1];
+        final FileObject fo = getProjectDir(doc);
+        doc.render(new Runnable() {
+
+            @Override
+            public void run() {
+                isText[0] = false;
         TokenHierarchy th = TokenHierarchy.get(doc);
         TokenSequence<XMLTokenId> xml = 
th.tokenSequence(XMLTokenId.language());
         xml.move(offset);
         xml.moveNext();
         Token<XMLTokenId> token = xml.token();
+
         // when it's not a value -> do nothing.
         if (token == null) {
+                   
             return;
         }
-        int tokenOff = xml.offset();
         if (token.id() == XMLTokenId.TEXT) {
-            //we are in element text
-            FileObject fo = getProjectDir(doc);
-            String text = token.text().toString();
-            if (fo != null && getPath(fo, text) != null) {
+                    isText[0] = true;
+                    ftokenOff[0] = xml.offset();
+                    ftext[0] = token.text().toString();
+                    if (fo != null && getPath(fo, ftext[0]) != null) {
                 xml.movePrevious();
                 token = xml.token();
                 if (token != null && token.id().equals(XMLTokenId.TAG) && 
TokenUtilities.equals(token.text(), ">")) {//NOI18N
                     xml.movePrevious();
                     token = xml.token();
                     if (token != null && token.id().equals(XMLTokenId.TAG) 
&& TokenUtilities.equals(token.text(), "<module")) {//NOI18N
-                        if (!text.endsWith("/pom.xml")) {
-                            text = text + "/pom.xml"; //NOI18N
+                                if (!ftext[0].endsWith("/pom.xml")) {
+                                    ftext[0] = ftext[0] + "/pom.xml"; 
//NOI18N
                         }
                     }
                 }
-                if (getPath(fo, text) != null) {
+                    }
+                }
+            }
+        });
+
+        if (isText[0]) {
+            //we are in element text
+            int tokenOff = ftokenOff[0];
+            String text = ftext[0];
+            
+            if (fo != null && getPath(fo, text) != null) {
                     FileObject file = getPath(fo, text);
                     NodeUtils.openPomFile(file);
                 }
-            }
             // urls get opened..
             if (text != null &&
                     (text.startsWith("http://";) || //NOI18N
@@ -273,22 +328,40 @@
         "# {1} - resolved value", 
         "Hint_prop_resolution={0} resolves to ''{1}''\nNavigate to 
definition.", 
         "Hint_prop_cannot=Cannot resolve expression\nNavigates to 
definition."})
-    public String getTooltipText(Document doc, int offset, HyperlinkType 
type) {
+    public String getTooltipText(final Document doc, final int offset, 
HyperlinkType type) {
 
+        final boolean[] isText = new boolean[1];
+        final int[] ftokenOff = new int[1];
+        final String[] ftext = new String[1];
+        
+        doc.render(new Runnable() {
+
+            @Override
+            public void run() {
+                isText[0] = false;
         TokenHierarchy th = TokenHierarchy.get(doc);
         TokenSequence<XMLTokenId> xml = 
th.tokenSequence(XMLTokenId.language());
         xml.move(offset);
         xml.moveNext();
         Token<XMLTokenId> token = xml.token();
+
         // when it's not a value -> do nothing.
         if (token == null) {
-            return null;
+                   
+                    return;
         }
-        int tokenOff = xml.offset();
+                if (token.id() == XMLTokenId.TEXT) {
+                    isText[0] = true;
+                    ftokenOff[0] = xml.offset();
+                    ftext[0] = token.text().toString();
+                }
+            }
+        });
  
-        if (token.id() == XMLTokenId.TEXT) {
+        if (isText[0]) {
             //we are in element text
-            String text = token.text().toString();
+            String text = ftext[0];
+            int tokenOff = ftokenOff[0];
             Tuple tup = findProperty(text, tokenOff, offset);
 
             if (tup != null) {

[hg] main-silver: #231655 always manipulate token hierarchies un...

Milos Kleint 07/02/2013

Project Features

About this Project

DB was started in November 2009, is owned by Antonin Nebuzelsky, and has 113 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close