Commits

Jan Lahoda  committed 1a8b094

Show remotely computed types in the Go to Type dialog

  • Participants
  • Parent commits ddd1660

Comments (0)

Files changed (10)

File bridges/jumpto/build.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
+<!-- for some information on what you could do (e.g. targets to override). -->
+<!-- If you delete this file and reopen the project it will be recreated. -->
+<project name="org.netbeans.modules.jackpot30.jumpto" default="netbeans" basedir=".">
+    <description>Builds, tests, and runs the project org.netbeans.modules.jackpot30.jumpto.</description>
+    <import file="nbproject/build-impl.xml"/>
+    <import file="${suite.dir}/findbugs-import.xml"/>
+</project>

File bridges/jumpto/manifest.mf

+Manifest-Version: 1.0
+OpenIDE-Module: org.netbeans.modules.jackpot30.jumpto
+OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/jumpto/Bundle.properties
+OpenIDE-Module-Specification-Version: 1.0
+

File bridges/jumpto/nbproject/build-impl.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+*** GENERATED FROM project.xml - DO NOT EDIT  ***
+***         EDIT ../build.xml INSTEAD         ***
+-->
+<project name="org.netbeans.modules.jackpot30.jumpto-impl" basedir="..">
+    <fail message="Please build using Ant 1.7.1 or higher.">
+        <condition>
+            <not>
+                <antversion atleast="1.7.1"/>
+            </not>
+        </condition>
+    </fail>
+    <property file="nbproject/private/suite-private.properties"/>
+    <property file="nbproject/suite.properties"/>
+    <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
+    <property file="${suite.dir}/nbproject/private/platform-private.properties"/>
+    <property file="${suite.dir}/nbproject/platform.properties"/>
+    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
+        <attribute name="name"/>
+        <attribute name="value"/>
+        <sequential>
+            <property name="@{name}" value="${@{value}}"/>
+        </sequential>
+    </macrodef>
+    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
+        <attribute name="property"/>
+        <attribute name="value"/>
+        <sequential>
+            <property name="@{property}" value="@{value}"/>
+        </sequential>
+    </macrodef>
+    <property file="${user.properties.file}"/>
+    <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
+    <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
+    <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
+    <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
+        <condition>
+            <not>
+                <contains string="${cluster.path.evaluated}" substring="platform"/>
+            </not>
+        </condition>
+    </fail>
+    <import file="${harness.dir}/build.xml"/>
+</project>

File bridges/jumpto/nbproject/genfiles.properties

+build.xml.data.CRC32=14c2e29c
+build.xml.script.CRC32=c7b5d9b7
+build.xml.stylesheet.CRC32=a56c6a5b@1.45
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=14c2e29c
+nbproject/build-impl.xml.script.CRC32=3404573f
+nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.45

File bridges/jumpto/nbproject/project.properties

+javac.source=1.6
+javac.compilerargs=-Xlint -Xlint:-serial

File bridges/jumpto/nbproject/project.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+    <type>org.netbeans.modules.apisupport.project</type>
+    <configuration>
+        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
+            <code-name-base>org.netbeans.modules.jackpot30.jumpto</code-name-base>
+            <suite-component/>
+            <module-dependencies>
+                <dependency>
+                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>1.28</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>7.5.0.3</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    <code-name-base>org.netbeans.modules.jackpot30.api</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <implementation-version/>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    <code-name-base>org.netbeans.modules.java.source</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <implementation-version/>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    <code-name-base>org.netbeans.modules.java.sourceui</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>1.20.0.1.17</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    <code-name-base>org.netbeans.modules.jeriglib</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>1.16</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    <code-name-base>org.netbeans.modules.jumpto</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <implementation-version/>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>1.35</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    <code-name-base>org.openide.filesystems</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>7.46</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    <code-name-base>org.openide.util</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>8.14</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    <code-name-base>org.openide.util.lookup</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>8.6</specification-version>
+                    </run-dependency>
+                </dependency>
+            </module-dependencies>
+            <public-packages/>
+        </data>
+    </configuration>
+</project>

File bridges/jumpto/nbproject/suite.properties

+suite.dir=${basedir}/../..

File bridges/jumpto/src/org/netbeans/modules/jackpot30/jumpto/Bundle.properties

+OpenIDE-Module-Name=jackpot 3.0 Jumpto Bridge

File bridges/jumpto/src/org/netbeans/modules/jackpot30/jumpto/RemoteGoToType.java

+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2011 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.jackpot30.jumpto;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.EnumSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.Modifier;
+import javax.swing.Icon;
+import org.codeviation.pojson.Pojson;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.api.java.source.ui.ElementIcons;
+import org.netbeans.api.java.source.ui.ElementOpen;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectUtils;
+import org.netbeans.modules.jackpot30.impl.WebUtilities;
+import org.netbeans.modules.jackpot30.impl.indexing.RemoteIndex;
+import org.netbeans.modules.java.source.ElementHandleAccessor;
+import org.netbeans.spi.jumpto.type.TypeDescriptor;
+import org.netbeans.spi.jumpto.type.TypeProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author lahvac
+ */
+@ServiceProvider(service=TypeProvider.class)
+public class RemoteGoToType implements TypeProvider {
+
+    @Override
+    public String name() {
+        return "Jackpot 3.0 Remote Index Type Provider";
+    }
+
+    @Override
+    public String getDisplayName() {
+        return "Jackpot 3.0 Remote Index Type Provider";
+    }
+
+    @Override
+    public void computeTypeNames(Context context, Result result) {
+        for (RemoteIndex ri : RemoteIndex.loadIndices()) {
+            try {
+                URI resolved = new URI(ri.remote.toExternalForm() + "/findType?path=" + WebUtilities.escapeForQuery(ri.remoteSegment) + "&prefix=" + WebUtilities.escapeForQuery(context.getText()));
+                @SuppressWarnings("unchecked") //XXX: should not trust something got from the network!
+                Map<String, List<String>> types = Pojson.load(LinkedHashMap.class, WebUtilities.requestStringResponse(resolved));
+
+                for (Entry<String, List<String>> e : types.entrySet()) {
+                    for (String binaryName : e.getValue()) {
+                        result.addResult(new RemoteTypeDescriptor(ri, e.getKey(), binaryName));
+                    }
+                }
+            } catch (URISyntaxException ex) {
+                Exceptions.printStackTrace(ex);
+            }
+        }
+    }
+
+    @Override
+    public void cancel() {
+    }
+
+    @Override
+    public void cleanup() {
+    }
+
+    private static final class RemoteTypeDescriptor extends TypeDescriptor {
+
+        private final RemoteIndex origin;
+        private final String relativePath;
+        private final String binaryName;
+        private final AtomicReference<FileObject> file = new AtomicReference<FileObject>();
+
+        public RemoteTypeDescriptor(RemoteIndex origin, String relativePath, String binaryName) {
+            this.origin = origin;
+            this.relativePath = relativePath;
+            this.binaryName = binaryName;
+        }
+
+        @Override
+        public String getSimpleName() {
+            int dollar = binaryName.lastIndexOf("$");
+            
+            if (dollar >= 0) return binaryName.substring(dollar + 1);
+            else {
+                int dot = binaryName.lastIndexOf(".");
+                
+                if (dot >= 0) return binaryName.substring(dot + 1);
+                else return binaryName;
+            }
+        }
+
+        @Override
+        public String getOuterName() {
+            int dollar = binaryName.lastIndexOf("$");
+            int dot = binaryName.lastIndexOf(".");
+
+            if (dollar >= 0 && dot >= 0) return binaryName.substring(dot + 1, dollar).replace("$", ".");
+            else return null;
+        }
+
+        @Override
+        public String getTypeName() {
+            if (getOuterName() != null)
+                return getSimpleName() + " in " + getOuterName();
+            else
+                return getSimpleName();
+        }
+
+        @Override
+        public String getContextName() {
+            int dot = binaryName.lastIndexOf(".");
+
+            if (dot >= 0) return " (" + binaryName.substring(0, dot) + ")";
+            else return "";
+        }
+
+        @Override
+        public Icon getIcon() {
+            return ElementIcons.getElementIcon(ElementKind.CLASS, EnumSet.noneOf(Modifier.class));
+        }
+
+        @Override
+        public String getProjectName() {
+            FileObject file = getFileObject();
+
+            if (file == null) return null;
+
+            Project prj = FileOwnerQuery.getOwner(file);
+
+            if (prj == null) return null;
+
+            return ProjectUtils.getInformation(prj).getDisplayName();
+        }
+
+        @Override
+        public Icon getProjectIcon() {
+            FileObject file = getFileObject();
+
+            if (file == null) return null;
+
+            Project prj = FileOwnerQuery.getOwner(file);
+
+            if (prj == null) return null;
+
+            return ProjectUtils.getInformation(prj).getIcon();
+        }
+
+        @Override
+        public FileObject getFileObject() {
+            FileObject f = this.file.get();
+
+            if (f == null) {
+                String fqn = binaryName;
+
+                if (fqn.contains("$")) {
+                    fqn = fqn.substring(0, fqn.indexOf("$"));
+                }
+
+                FileObject originFolder = FileUtil.toFileObject(FileUtil.normalizeFile(new File(origin.folder)));
+
+                if (originFolder != null) f = originFolder.getFileObject(relativePath + "/" + fqn.replace('.', '/') + ".java");
+                if (f != null) this.file.set(f);
+            }
+
+            return f;
+        }
+
+        @Override
+        public int getOffset() {
+            return 0;
+        }
+
+        @Override
+        public void open() {
+            FileObject file = getFileObject();
+
+            if (file == null) return ; //XXX tell to the user
+
+            ClasspathInfo cpInfo = ClasspathInfo.create(file);
+            ElementHandle<?> handle = ElementHandleAccessor.INSTANCE.create(ElementKind.CLASS, binaryName);
+
+            ElementOpen.open(cpInfo, handle);
+        }
+
+    }
+}

File nbproject/project.properties

     ${project.org.netbeans.modules.libs.jerig}:\
     ${project.org.netbeans.modules.jackpot30.java.hints}:\
     ${project.org.netbeans.modules.jackpot30.refactoring}:\
-    ${project.org.netbeans.modules.jackpot30.apisupport}
+    ${project.org.netbeans.modules.jackpot30.apisupport}:\
+    ${project.org.netbeans.modules.jackpot30.jumpto}
 project.org.netbeans.modules.jackpot30.api=api
 project.org.netbeans.modules.jackpot30.apisupport=bridges/apisupport
 project.org.netbeans.modules.jackpot30.file=file
 project.org.netbeans.modules.jackpot30.help=help
 project.org.netbeans.modules.jackpot30.hintsimpl=hintsimpl
 project.org.netbeans.modules.jackpot30.java.hints=bridges/java.hints
+project.org.netbeans.modules.jackpot30.jumpto=bridges/jumpto
 project.org.netbeans.modules.jackpot30.kit=kit
 project.org.netbeans.modules.jackpot30.refactoring=bridges/refactoring
 project.org.netbeans.modules.jackpot30.transformers=transformer