Using SourceUtils.getJVMSignature to get an Element signature
authorJan Lahoda <jlahoda@netbeans.org>
Fri, 02 Sep 2011 16:13:09 +0200
changeset 68791ddd467539f
parent 686 b0d6c5ef735f
child 688 4386b7bcc616
Using SourceUtils.getJVMSignature to get an Element signature
remoting/ide/usages/manifest.mf
remoting/ide/usages/nbproject/project.xml
remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Common.java
remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java
remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/Common.java
     1.1 --- a/remoting/ide/usages/manifest.mf	Tue Aug 23 19:16:11 2011 +0200
     1.2 +++ b/remoting/ide/usages/manifest.mf	Fri Sep 02 16:13:09 2011 +0200
     1.3 @@ -3,5 +3,5 @@
     1.4  OpenIDE-Module: org.netbeans.modules.jackpot30.ide.usages
     1.5  OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/ide/usages/Bundle.properties
     1.6  OpenIDE-Module-Requires: org.openide.windows.WindowManager
     1.7 -OpenIDE-Module-Specification-Version: 1.5
     1.8 +OpenIDE-Module-Specification-Version: 1.6
     1.9  
     2.1 --- a/remoting/ide/usages/nbproject/project.xml	Tue Aug 23 19:16:11 2011 +0200
     2.2 +++ b/remoting/ide/usages/nbproject/project.xml	Fri Sep 02 16:13:09 2011 +0200
     2.3 @@ -54,7 +54,7 @@
     2.4                      <build-prerequisite/>
     2.5                      <compile-dependency/>
     2.6                      <run-dependency>
     2.7 -                        <specification-version>0.81.0.17.15.6</specification-version>
     2.8 +                        <specification-version>0.84</specification-version>
     2.9                      </run-dependency>
    2.10                  </dependency>
    2.11                  <dependency>
     3.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Common.java	Tue Aug 23 19:16:11 2011 +0200
     3.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Common.java	Fri Sep 02 16:13:09 2011 +0200
     3.3 @@ -41,12 +41,11 @@
     3.4   */
     3.5  package org.netbeans.modules.jackpot30.ide.usages;
     3.6  
     3.7 -import java.lang.reflect.Field;
     3.8  import java.util.EnumSet;
     3.9  import java.util.Set;
    3.10  import javax.lang.model.element.ElementKind;
    3.11  import org.netbeans.api.java.source.ElementHandle;
    3.12 -import org.openide.util.Exceptions;
    3.13 +import org.netbeans.api.java.source.SourceUtils;
    3.14  
    3.15  /**XXX: Copied between indexing and ide!
    3.16   *
    3.17 @@ -64,25 +63,11 @@
    3.18  
    3.19          result.append(h.getKind());
    3.20  
    3.21 -        try {
    3.22 -            Field signaturesField = ElementHandle.class.getDeclaredField("signatures");
    3.23 +        String[] signatures = SourceUtils.getJVMSignature(h);
    3.24  
    3.25 -            signaturesField.setAccessible(true);
    3.26 -
    3.27 -            String[] signatures = (String[]) signaturesField.get(h);
    3.28 -
    3.29 -            for (String sig : signatures) {
    3.30 -                result.append(":");
    3.31 -                result.append(sig);
    3.32 -            }
    3.33 -        } catch (IllegalArgumentException ex) {
    3.34 -            Exceptions.printStackTrace(ex);
    3.35 -        } catch (IllegalAccessException ex) {
    3.36 -            Exceptions.printStackTrace(ex);
    3.37 -        } catch (NoSuchFieldException ex) {
    3.38 -            Exceptions.printStackTrace(ex);
    3.39 -        } catch (SecurityException ex) {
    3.40 -            Exceptions.printStackTrace(ex);
    3.41 +        for (String sig : signatures) {
    3.42 +            result.append(":");
    3.43 +            result.append(sig);
    3.44          }
    3.45  
    3.46          return result.toString();
     4.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java	Tue Aug 23 19:16:11 2011 +0200
     4.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java	Fri Sep 02 16:13:09 2011 +0200
     4.3 @@ -48,12 +48,9 @@
     4.4  import java.awt.Insets;
     4.5  import java.awt.event.ActionEvent;
     4.6  import java.awt.event.ActionListener;
     4.7 -import java.io.File;
     4.8  import java.io.IOException;
     4.9 -import java.lang.reflect.Field;
    4.10  import java.net.URI;
    4.11  import java.net.URISyntaxException;
    4.12 -import java.net.URL;
    4.13  import java.util.ArrayList;
    4.14  import java.util.Collection;
    4.15  import java.util.EnumSet;
    4.16 @@ -94,7 +91,6 @@
    4.17  import org.openide.awt.ActionReferences;
    4.18  import org.openide.awt.ActionID;
    4.19  import org.openide.filesystems.FileObject;
    4.20 -import org.openide.filesystems.FileUtil;
    4.21  import org.openide.filesystems.URLMapper;
    4.22  import org.openide.nodes.Node;
    4.23  import org.openide.util.Cancellable;
    4.24 @@ -222,36 +218,6 @@
    4.25          return result;
    4.26      }
    4.27      
    4.28 -    //XXX:
    4.29 -    public static String serialize(ElementHandle<?> h) {
    4.30 -        StringBuilder result = new StringBuilder();
    4.31 -
    4.32 -        result.append(h.getKind());
    4.33 -
    4.34 -        try {
    4.35 -            Field signaturesField = ElementHandle.class.getDeclaredField("signatures");
    4.36 -
    4.37 -            signaturesField.setAccessible(true);
    4.38 -
    4.39 -            String[] signatures = (String[]) signaturesField.get(h);
    4.40 -
    4.41 -            for (String sig : signatures) {
    4.42 -                result.append(":");
    4.43 -                result.append(sig);
    4.44 -            }
    4.45 -        } catch (IllegalArgumentException ex) {
    4.46 -            Exceptions.printStackTrace(ex);
    4.47 -        } catch (IllegalAccessException ex) {
    4.48 -            Exceptions.printStackTrace(ex);
    4.49 -        } catch (NoSuchFieldException ex) {
    4.50 -            Exceptions.printStackTrace(ex);
    4.51 -        } catch (SecurityException ex) {
    4.52 -            Exceptions.printStackTrace(ex);
    4.53 -        }
    4.54 -
    4.55 -        return result.toString();
    4.56 -    }
    4.57 -
    4.58      public static final class ElementDescription {
    4.59          public final ElementHandle<?> element;
    4.60          public final String displayName;
    4.61 @@ -324,7 +290,7 @@
    4.62  
    4.63          @Override public void run() {
    4.64              try {
    4.65 -                final String serialized = serialize(toSearch);
    4.66 +                final String serialized = Common.serialize(toSearch);
    4.67  
    4.68                  Set<FileObject> resultSet = new HashSet<FileObject>();
    4.69                  List<FileObject> result = new ArrayList<FileObject>();
     5.1 --- a/remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/Common.java	Tue Aug 23 19:16:11 2011 +0200
     5.2 +++ b/remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/Common.java	Fri Sep 02 16:13:09 2011 +0200
     5.3 @@ -41,12 +41,11 @@
     5.4   */
     5.5  package org.netbeans.modules.jackpot30.indexer.usages;
     5.6  
     5.7 -import java.lang.reflect.Field;
     5.8  import java.util.EnumSet;
     5.9  import java.util.Set;
    5.10  import javax.lang.model.element.ElementKind;
    5.11  import org.netbeans.api.java.source.ElementHandle;
    5.12 -import org.openide.util.Exceptions;
    5.13 +import org.netbeans.api.java.source.SourceUtils;
    5.14  
    5.15  /**XXX: Copied between indexing and ide!
    5.16   *
    5.17 @@ -64,25 +63,11 @@
    5.18  
    5.19          result.append(h.getKind());
    5.20  
    5.21 -        try {
    5.22 -            Field signaturesField = ElementHandle.class.getDeclaredField("signatures");
    5.23 +        String[] signatures = SourceUtils.getJVMSignature(h);
    5.24  
    5.25 -            signaturesField.setAccessible(true);
    5.26 -
    5.27 -            String[] signatures = (String[]) signaturesField.get(h);
    5.28 -
    5.29 -            for (String sig : signatures) {
    5.30 -                result.append(":");
    5.31 -                result.append(sig);
    5.32 -            }
    5.33 -        } catch (IllegalArgumentException ex) {
    5.34 -            Exceptions.printStackTrace(ex);
    5.35 -        } catch (IllegalAccessException ex) {
    5.36 -            Exceptions.printStackTrace(ex);
    5.37 -        } catch (NoSuchFieldException ex) {
    5.38 -            Exceptions.printStackTrace(ex);
    5.39 -        } catch (SecurityException ex) {
    5.40 -            Exceptions.printStackTrace(ex);
    5.41 +        for (String sig : signatures) {
    5.42 +            result.append(":");
    5.43 +            result.append(sig);
    5.44          }
    5.45  
    5.46          return result.toString();