Starting with migration of remoting from its own action/window into standard FU
1.1 --- a/remoting/ide/usages/nbproject/genfiles.properties Fri Aug 10 22:46:58 2012 +0200
1.2 +++ b/remoting/ide/usages/nbproject/genfiles.properties Wed Aug 15 14:33:00 2012 +0200
1.3 @@ -3,6 +3,6 @@
1.4 build.xml.stylesheet.CRC32=a56c6a5b@2.49
1.5 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
1.6 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
1.7 -nbproject/build-impl.xml.data.CRC32=e216ee19
1.8 +nbproject/build-impl.xml.data.CRC32=0a4dbc03
1.9 nbproject/build-impl.xml.script.CRC32=583fd407
1.10 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49
1.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.53
2.1 --- a/remoting/ide/usages/nbproject/project.xml Fri Aug 10 22:46:58 2012 +0200
2.2 +++ b/remoting/ide/usages/nbproject/project.xml Wed Aug 15 14:33:00 2012 +0200
2.3 @@ -102,6 +102,32 @@
2.4 </run-dependency>
2.5 </dependency>
2.6 <dependency>
2.7 + <code-name-base>org.netbeans.modules.queries</code-name-base>
2.8 + <build-prerequisite/>
2.9 + <compile-dependency/>
2.10 + <run-dependency>
2.11 + <release-version>1</release-version>
2.12 + <specification-version>1.29</specification-version>
2.13 + </run-dependency>
2.14 + </dependency>
2.15 + <dependency>
2.16 + <code-name-base>org.netbeans.modules.refactoring.api</code-name-base>
2.17 + <build-prerequisite/>
2.18 + <compile-dependency/>
2.19 + <run-dependency>
2.20 + <specification-version>1.29.0.1</specification-version>
2.21 + </run-dependency>
2.22 + </dependency>
2.23 + <dependency>
2.24 + <code-name-base>org.netbeans.modules.refactoring.java</code-name-base>
2.25 + <build-prerequisite/>
2.26 + <compile-dependency/>
2.27 + <run-dependency>
2.28 + <release-version>1</release-version>
2.29 + <implementation-version/>
2.30 + </run-dependency>
2.31 + </dependency>
2.32 + <dependency>
2.33 <code-name-base>org.netbeans.modules.settings</code-name-base>
2.34 <build-prerequisite/>
2.35 <compile-dependency/>
3.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Bundle.properties Fri Aug 10 22:46:58 2012 +0200
3.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Bundle.properties Wed Aug 15 14:33:00 2012 +0200
3.3 @@ -1,49 +1,1 @@
3.4 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3.5 -#
3.6 -# Copyright 2011 Oracle and/or its affiliates. All rights reserved.
3.7 -#
3.8 -# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
3.9 -# Other names may be trademarks of their respective owners.
3.10 -#
3.11 -# The contents of this file are subject to the terms of either the GNU
3.12 -# General Public License Version 2 only ("GPL") or the Common
3.13 -# Development and Distribution License("CDDL") (collectively, the
3.14 -# "License"). You may not use this file except in compliance with the
3.15 -# License. You can obtain a copy of the License at
3.16 -# http://www.netbeans.org/cddl-gplv2.html
3.17 -# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
3.18 -# specific language governing permissions and limitations under the
3.19 -# License. When distributing the software, include this License Header
3.20 -# Notice in each file and include the License file at
3.21 -# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
3.22 -# particular file as subject to the "Classpath" exception as provided
3.23 -# by Oracle in the GPL Version 2 section of the License file that
3.24 -# accompanied this code. If applicable, add the following below the
3.25 -# License Header, with the fields enclosed by brackets [] replaced by
3.26 -# your own identifying information:
3.27 -# "Portions Copyrighted [year] [name of copyright owner]"
3.28 -#
3.29 -# If you wish your version of this file to be governed by only the CDDL
3.30 -# or only the GPL Version 2, indicate your decision by adding
3.31 -# "[Contributor] elects to include this software in this distribution
3.32 -# under the [CDDL or GPL Version 2] license." If you do not indicate a
3.33 -# single choice of license, a recipient has the option to distribute
3.34 -# your version of this file under either the CDDL, the GPL Version 2 or
3.35 -# to extend the choice of license to its licensees as provided above.
3.36 -# However, if you add GPL Version 2 code and therefore, elected the GPL
3.37 -# Version 2 license, then the option applies only if the new code is
3.38 -# made subject to such option by the copyright holder.
3.39 -#
3.40 -# Contributor(s):
3.41 -#
3.42 -# Portions Copyrighted 2011 Sun Microsystems, Inc.
3.43 -#
3.44 -CTL_RemoteUsagesWindowAction=RemoteUsagesWindow
3.45 -CTL_RemoteUsagesWindowTopComponent=RemoteUsagesWindow Window
3.46 -HINT_RemoteUsagesWindowTopComponent=This is a RemoteUsagesWindow window
3.47 OpenIDE-Module-Name=Jackpot 3.0 Usage IDE
3.48 -MethodOptions.usages.text=Usages
3.49 -MethodOptions.overriding.text=Overriding methods
3.50 -MethodOptions.fromBaseClass.text=<html>Search from base class ({0})
3.51 -ClassOptions.usages.text=Usages
3.52 -ClassOptions.subclasses.text=Subclasses
4.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/ClassOptions.form Fri Aug 10 22:46:58 2012 +0200
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,73 +0,0 @@
4.4 -<?xml version="1.0" encoding="UTF-8" ?>
4.5 -
4.6 -<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4.7 - <NonVisualComponents>
4.8 - <Component class="javax.swing.ButtonGroup" name="buttonGroup">
4.9 - </Component>
4.10 - </NonVisualComponents>
4.11 - <AuxValues>
4.12 - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
4.13 - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
4.14 - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
4.15 - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
4.16 - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
4.17 - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
4.18 - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
4.19 - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
4.20 - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
4.21 - </AuxValues>
4.22 -
4.23 - <Layout>
4.24 - <DimensionLayout dim="0">
4.25 - <Group type="103" groupAlignment="0" attributes="0">
4.26 - <Group type="102" attributes="0">
4.27 - <EmptySpace max="-2" attributes="0"/>
4.28 - <Group type="103" groupAlignment="0" attributes="0">
4.29 - <Component id="usages" alignment="0" min="-2" max="-2" attributes="0"/>
4.30 - <Component id="subclasses" alignment="0" min="-2" max="-2" attributes="0"/>
4.31 - </Group>
4.32 - <EmptySpace max="32767" attributes="0"/>
4.33 - </Group>
4.34 - </Group>
4.35 - </DimensionLayout>
4.36 - <DimensionLayout dim="1">
4.37 - <Group type="103" groupAlignment="0" attributes="0">
4.38 - <Group type="102" alignment="0" attributes="0">
4.39 - <EmptySpace max="-2" attributes="0"/>
4.40 - <Component id="usages" min="-2" max="-2" attributes="0"/>
4.41 - <EmptySpace type="unrelated" max="-2" attributes="0"/>
4.42 - <Component id="subclasses" min="-2" max="-2" attributes="0"/>
4.43 - <EmptySpace max="32767" attributes="0"/>
4.44 - </Group>
4.45 - </Group>
4.46 - </DimensionLayout>
4.47 - </Layout>
4.48 - <SubComponents>
4.49 - <Component class="javax.swing.JRadioButton" name="usages">
4.50 - <Properties>
4.51 - <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
4.52 - <ComponentRef name="buttonGroup"/>
4.53 - </Property>
4.54 - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
4.55 - <ResourceString bundle="org/netbeans/modules/jackpot30/ide/usages/Bundle.properties" key="ClassOptions.usages.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}", {arguments})"/>
4.56 - </Property>
4.57 - </Properties>
4.58 - <Events>
4.59 - <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="usagesItemStateChanged"/>
4.60 - </Events>
4.61 - </Component>
4.62 - <Component class="javax.swing.JRadioButton" name="subclasses">
4.63 - <Properties>
4.64 - <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
4.65 - <ComponentRef name="buttonGroup"/>
4.66 - </Property>
4.67 - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
4.68 - <ResourceString bundle="org/netbeans/modules/jackpot30/ide/usages/Bundle.properties" key="ClassOptions.subclasses.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}", {arguments})"/>
4.69 - </Property>
4.70 - </Properties>
4.71 - <Events>
4.72 - <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="subclassesItemStateChanged"/>
4.73 - </Events>
4.74 - </Component>
4.75 - </SubComponents>
4.76 -</Form>
5.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/ClassOptions.java Fri Aug 10 22:46:58 2012 +0200
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,130 +0,0 @@
5.4 -/*
5.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5.6 - *
5.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5.8 - *
5.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
5.10 - * Other names may be trademarks of their respective owners.
5.11 - *
5.12 - * The contents of this file are subject to the terms of either the GNU
5.13 - * General Public License Version 2 only ("GPL") or the Common
5.14 - * Development and Distribution License("CDDL") (collectively, the
5.15 - * "License"). You may not use this file except in compliance with the
5.16 - * License. You can obtain a copy of the License at
5.17 - * http://www.netbeans.org/cddl-gplv2.html
5.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
5.19 - * specific language governing permissions and limitations under the
5.20 - * License. When distributing the software, include this License Header
5.21 - * Notice in each file and include the License file at
5.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
5.23 - * particular file as subject to the "Classpath" exception as provided
5.24 - * by Oracle in the GPL Version 2 section of the License file that
5.25 - * accompanied this code. If applicable, add the following below the
5.26 - * License Header, with the fields enclosed by brackets [] replaced by
5.27 - * your own identifying information:
5.28 - * "Portions Copyrighted [year] [name of copyright owner]"
5.29 - *
5.30 - * If you wish your version of this file to be governed by only the CDDL
5.31 - * or only the GPL Version 2, indicate your decision by adding
5.32 - * "[Contributor] elects to include this software in this distribution
5.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
5.34 - * single choice of license, a recipient has the option to distribute
5.35 - * your version of this file under either the CDDL, the GPL Version 2 or
5.36 - * to extend the choice of license to its licensees as provided above.
5.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
5.38 - * Version 2 license, then the option applies only if the new code is
5.39 - * made subject to such option by the copyright holder.
5.40 - *
5.41 - * Contributor(s):
5.42 - *
5.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
5.44 - */
5.45 -package org.netbeans.modules.jackpot30.ide.usages;
5.46 -
5.47 -import java.util.Set;
5.48 -
5.49 -/**
5.50 - *
5.51 - * @author lahvac
5.52 - */
5.53 -public class ClassOptions extends javax.swing.JPanel {
5.54 -
5.55 - private final Set<RemoteUsages.SearchOptions> options;
5.56 -
5.57 - public ClassOptions(Set<RemoteUsages.SearchOptions> options) {
5.58 - this.options = options;
5.59 - initComponents();
5.60 - usages.setSelected(true);
5.61 - }
5.62 -
5.63 - /** This method is called from within the constructor to
5.64 - * initialize the form.
5.65 - * WARNING: Do NOT modify this code. The content of this method is
5.66 - * always regenerated by the Form Editor.
5.67 - */
5.68 - @SuppressWarnings("unchecked")
5.69 - // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
5.70 - private void initComponents() {
5.71 -
5.72 - buttonGroup = new javax.swing.ButtonGroup();
5.73 - usages = new javax.swing.JRadioButton();
5.74 - subclasses = new javax.swing.JRadioButton();
5.75 -
5.76 - buttonGroup.add(usages);
5.77 - usages.setText(org.openide.util.NbBundle.getMessage(ClassOptions.class, "ClassOptions.usages.text", new Object[] {})); // NOI18N
5.78 - usages.addItemListener(new java.awt.event.ItemListener() {
5.79 - public void itemStateChanged(java.awt.event.ItemEvent evt) {
5.80 - usagesItemStateChanged(evt);
5.81 - }
5.82 - });
5.83 -
5.84 - buttonGroup.add(subclasses);
5.85 - subclasses.setText(org.openide.util.NbBundle.getMessage(ClassOptions.class, "ClassOptions.subclasses.text", new Object[] {})); // NOI18N
5.86 - subclasses.addItemListener(new java.awt.event.ItemListener() {
5.87 - public void itemStateChanged(java.awt.event.ItemEvent evt) {
5.88 - subclassesItemStateChanged(evt);
5.89 - }
5.90 - });
5.91 -
5.92 - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
5.93 - this.setLayout(layout);
5.94 - layout.setHorizontalGroup(
5.95 - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
5.96 - .addGroup(layout.createSequentialGroup()
5.97 - .addContainerGap()
5.98 - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
5.99 - .addComponent(usages)
5.100 - .addComponent(subclasses))
5.101 - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
5.102 - );
5.103 - layout.setVerticalGroup(
5.104 - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
5.105 - .addGroup(layout.createSequentialGroup()
5.106 - .addContainerGap()
5.107 - .addComponent(usages)
5.108 - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
5.109 - .addComponent(subclasses)
5.110 - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
5.111 - );
5.112 - }// </editor-fold>//GEN-END:initComponents
5.113 -
5.114 - private void usagesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_usagesItemStateChanged
5.115 - if (usages.isSelected())
5.116 - options.add(RemoteUsages.SearchOptions.USAGES);
5.117 - else
5.118 - options.remove(RemoteUsages.SearchOptions.USAGES);
5.119 - }//GEN-LAST:event_usagesItemStateChanged
5.120 -
5.121 - private void subclassesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_subclassesItemStateChanged
5.122 - if (subclasses.isSelected())
5.123 - options.add(RemoteUsages.SearchOptions.SUB);
5.124 - else
5.125 - options.remove(RemoteUsages.SearchOptions.SUB);
5.126 - }//GEN-LAST:event_subclassesItemStateChanged
5.127 -
5.128 - // Variables declaration - do not modify//GEN-BEGIN:variables
5.129 - private javax.swing.ButtonGroup buttonGroup;
5.130 - private javax.swing.JRadioButton subclasses;
5.131 - private javax.swing.JRadioButton usages;
5.132 - // End of variables declaration//GEN-END:variables
5.133 -}
6.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/MethodOptions.form Fri Aug 10 22:46:58 2012 +0200
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,78 +0,0 @@
6.4 -<?xml version="1.0" encoding="UTF-8" ?>
6.5 -
6.6 -<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
6.7 - <AuxValues>
6.8 - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6.9 - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
6.10 - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
6.11 - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
6.12 - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
6.13 - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
6.14 - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
6.15 - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
6.16 - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
6.17 - </AuxValues>
6.18 -
6.19 - <Layout>
6.20 - <DimensionLayout dim="0">
6.21 - <Group type="103" groupAlignment="0" attributes="0">
6.22 - <Group type="102" attributes="0">
6.23 - <EmptySpace max="-2" attributes="0"/>
6.24 - <Group type="103" groupAlignment="0" attributes="0">
6.25 - <Component id="usages" alignment="0" min="-2" max="-2" attributes="0"/>
6.26 - <Component id="overriding" alignment="0" min="-2" max="-2" attributes="0"/>
6.27 - <Component id="fromBaseClass" alignment="0" min="-2" max="-2" attributes="0"/>
6.28 - </Group>
6.29 - <EmptySpace max="32767" attributes="0"/>
6.30 - </Group>
6.31 - </Group>
6.32 - </DimensionLayout>
6.33 - <DimensionLayout dim="1">
6.34 - <Group type="103" groupAlignment="0" attributes="0">
6.35 - <Group type="102" alignment="0" attributes="0">
6.36 - <EmptySpace max="-2" attributes="0"/>
6.37 - <Component id="usages" min="-2" max="-2" attributes="0"/>
6.38 - <EmptySpace type="unrelated" max="-2" attributes="0"/>
6.39 - <Component id="overriding" min="-2" max="-2" attributes="0"/>
6.40 - <EmptySpace type="separate" max="-2" attributes="0"/>
6.41 - <Component id="fromBaseClass" min="-2" max="-2" attributes="0"/>
6.42 - <EmptySpace max="32767" attributes="0"/>
6.43 - </Group>
6.44 - </Group>
6.45 - </DimensionLayout>
6.46 - </Layout>
6.47 - <SubComponents>
6.48 - <Component class="javax.swing.JCheckBox" name="usages">
6.49 - <Properties>
6.50 - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
6.51 - <ResourceString bundle="org/netbeans/modules/jackpot30/ide/usages/Bundle.properties" key="MethodOptions.usages.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
6.52 - </Property>
6.53 - </Properties>
6.54 - <Events>
6.55 - <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="usagesItemStateChanged"/>
6.56 - </Events>
6.57 - </Component>
6.58 - <Component class="javax.swing.JCheckBox" name="overriding">
6.59 - <Properties>
6.60 - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
6.61 - <ResourceString bundle="org/netbeans/modules/jackpot30/ide/usages/Bundle.properties" key="MethodOptions.overriding.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
6.62 - </Property>
6.63 - </Properties>
6.64 - <Events>
6.65 - <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="overridingItemStateChanged"/>
6.66 - </Events>
6.67 - </Component>
6.68 - <Component class="javax.swing.JCheckBox" name="fromBaseClass">
6.69 - <Properties>
6.70 - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
6.71 - <ResourceString bundle="org/netbeans/modules/jackpot30/ide/usages/Bundle.properties" key="MethodOptions.fromBaseClass.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}", {arguments})">
6.72 - <Argument index="0" javacode="superMethod"/>
6.73 - </ResourceString>
6.74 - </Property>
6.75 - </Properties>
6.76 - <Events>
6.77 - <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="fromBaseClassItemStateChanged"/>
6.78 - </Events>
6.79 - </Component>
6.80 - </SubComponents>
6.81 -</Form>
7.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/MethodOptions.java Fri Aug 10 22:46:58 2012 +0200
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,152 +0,0 @@
7.4 -/*
7.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
7.6 - *
7.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
7.8 - *
7.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7.10 - * Other names may be trademarks of their respective owners.
7.11 - *
7.12 - * The contents of this file are subject to the terms of either the GNU
7.13 - * General Public License Version 2 only ("GPL") or the Common
7.14 - * Development and Distribution License("CDDL") (collectively, the
7.15 - * "License"). You may not use this file except in compliance with the
7.16 - * License. You can obtain a copy of the License at
7.17 - * http://www.netbeans.org/cddl-gplv2.html
7.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
7.19 - * specific language governing permissions and limitations under the
7.20 - * License. When distributing the software, include this License Header
7.21 - * Notice in each file and include the License file at
7.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
7.23 - * particular file as subject to the "Classpath" exception as provided
7.24 - * by Oracle in the GPL Version 2 section of the License file that
7.25 - * accompanied this code. If applicable, add the following below the
7.26 - * License Header, with the fields enclosed by brackets [] replaced by
7.27 - * your own identifying information:
7.28 - * "Portions Copyrighted [year] [name of copyright owner]"
7.29 - *
7.30 - * If you wish your version of this file to be governed by only the CDDL
7.31 - * or only the GPL Version 2, indicate your decision by adding
7.32 - * "[Contributor] elects to include this software in this distribution
7.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
7.34 - * single choice of license, a recipient has the option to distribute
7.35 - * your version of this file under either the CDDL, the GPL Version 2 or
7.36 - * to extend the choice of license to its licensees as provided above.
7.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
7.38 - * Version 2 license, then the option applies only if the new code is
7.39 - * made subject to such option by the copyright holder.
7.40 - *
7.41 - * Contributor(s):
7.42 - *
7.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
7.44 - */
7.45 -package org.netbeans.modules.jackpot30.ide.usages;
7.46 -
7.47 -import java.util.Set;
7.48 -
7.49 -/**
7.50 - *
7.51 - * @author lahvac
7.52 - */
7.53 -public class MethodOptions extends javax.swing.JPanel {
7.54 -
7.55 - private final String superMethod;
7.56 - private final Set<RemoteUsages.SearchOptions> options;
7.57 -
7.58 - public MethodOptions(RemoteUsages.ElementDescription element, Set<RemoteUsages.SearchOptions> options) {
7.59 - superMethod = element.superMethodDisplayName != null ? element.superMethodDisplayName : "";
7.60 - this.options = options;
7.61 -
7.62 - initComponents();
7.63 -
7.64 - if (element.superMethod == null) fromBaseClass.setVisible(false);
7.65 - else fromBaseClass.setSelected(true);
7.66 -
7.67 - usages.setSelected(true);
7.68 - }
7.69 -
7.70 - /** This method is called from within the constructor to
7.71 - * initialize the form.
7.72 - * WARNING: Do NOT modify this code. The content of this method is
7.73 - * always regenerated by the Form Editor.
7.74 - */
7.75 - @SuppressWarnings("unchecked")
7.76 - // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
7.77 - private void initComponents() {
7.78 -
7.79 - usages = new javax.swing.JCheckBox();
7.80 - overriding = new javax.swing.JCheckBox();
7.81 - fromBaseClass = new javax.swing.JCheckBox();
7.82 -
7.83 - usages.setText(org.openide.util.NbBundle.getMessage(MethodOptions.class, "MethodOptions.usages.text")); // NOI18N
7.84 - usages.addItemListener(new java.awt.event.ItemListener() {
7.85 - public void itemStateChanged(java.awt.event.ItemEvent evt) {
7.86 - usagesItemStateChanged(evt);
7.87 - }
7.88 - });
7.89 -
7.90 - overriding.setText(org.openide.util.NbBundle.getMessage(MethodOptions.class, "MethodOptions.overriding.text")); // NOI18N
7.91 - overriding.addItemListener(new java.awt.event.ItemListener() {
7.92 - public void itemStateChanged(java.awt.event.ItemEvent evt) {
7.93 - overridingItemStateChanged(evt);
7.94 - }
7.95 - });
7.96 -
7.97 - fromBaseClass.setText(org.openide.util.NbBundle.getMessage(MethodOptions.class, "MethodOptions.fromBaseClass.text", new Object[] {superMethod})); // NOI18N
7.98 - fromBaseClass.addItemListener(new java.awt.event.ItemListener() {
7.99 - public void itemStateChanged(java.awt.event.ItemEvent evt) {
7.100 - fromBaseClassItemStateChanged(evt);
7.101 - }
7.102 - });
7.103 -
7.104 - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
7.105 - this.setLayout(layout);
7.106 - layout.setHorizontalGroup(
7.107 - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
7.108 - .addGroup(layout.createSequentialGroup()
7.109 - .addContainerGap()
7.110 - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
7.111 - .addComponent(usages)
7.112 - .addComponent(overriding)
7.113 - .addComponent(fromBaseClass))
7.114 - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
7.115 - );
7.116 - layout.setVerticalGroup(
7.117 - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
7.118 - .addGroup(layout.createSequentialGroup()
7.119 - .addContainerGap()
7.120 - .addComponent(usages)
7.121 - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
7.122 - .addComponent(overriding)
7.123 - .addGap(18, 18, 18)
7.124 - .addComponent(fromBaseClass)
7.125 - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
7.126 - );
7.127 - }// </editor-fold>//GEN-END:initComponents
7.128 -
7.129 - private void usagesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_usagesItemStateChanged
7.130 - if (usages.isSelected())
7.131 - options.add(RemoteUsages.SearchOptions.USAGES);
7.132 - else
7.133 - options.remove(RemoteUsages.SearchOptions.USAGES);
7.134 - }//GEN-LAST:event_usagesItemStateChanged
7.135 -
7.136 - private void overridingItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_overridingItemStateChanged
7.137 - if (overriding.isSelected())
7.138 - options.add(RemoteUsages.SearchOptions.SUB);
7.139 - else
7.140 - options.remove(RemoteUsages.SearchOptions.SUB);
7.141 - }//GEN-LAST:event_overridingItemStateChanged
7.142 -
7.143 - private void fromBaseClassItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fromBaseClassItemStateChanged
7.144 - if (fromBaseClass.isSelected())
7.145 - options.add(RemoteUsages.SearchOptions.FROM_BASE);
7.146 - else
7.147 - options.remove(RemoteUsages.SearchOptions.FROM_BASE);
7.148 - }//GEN-LAST:event_fromBaseClassItemStateChanged
7.149 -
7.150 - // Variables declaration - do not modify//GEN-BEGIN:variables
7.151 - private javax.swing.JCheckBox fromBaseClass;
7.152 - private javax.swing.JCheckBox overriding;
7.153 - private javax.swing.JCheckBox usages;
7.154 - // End of variables declaration//GEN-END:variables
7.155 -}
8.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Nodes.java Fri Aug 10 22:46:58 2012 +0200
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,657 +0,0 @@
8.4 -/*
8.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8.6 - *
8.7 - * Copyright 2010-2011 Oracle and/or its affiliates. All rights reserved.
8.8 - *
8.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8.10 - * Other names may be trademarks of their respective owners.
8.11 - *
8.12 - * The contents of this file are subject to the terms of either the GNU
8.13 - * General Public License Version 2 only ("GPL") or the Common
8.14 - * Development and Distribution License("CDDL") (collectively, the
8.15 - * "License"). You may not use this file except in compliance with the
8.16 - * License. You can obtain a copy of the License at
8.17 - * http://www.netbeans.org/cddl-gplv2.html
8.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
8.19 - * specific language governing permissions and limitations under the
8.20 - * License. When distributing the software, include this License Header
8.21 - * Notice in each file and include the License file at
8.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
8.23 - * particular file as subject to the "Classpath" exception as provided
8.24 - * by Oracle in the GPL Version 2 section of the License file that
8.25 - * accompanied this code. If applicable, add the following below the
8.26 - * License Header, with the fields enclosed by brackets [] replaced by
8.27 - * your own identifying information:
8.28 - * "Portions Copyrighted [year] [name of copyright owner]"
8.29 - *
8.30 - * If you wish your version of this file to be governed by only the CDDL
8.31 - * or only the GPL Version 2, indicate your decision by adding
8.32 - * "[Contributor] elects to include this software in this distribution
8.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
8.34 - * single choice of license, a recipient has the option to distribute
8.35 - * your version of this file under either the CDDL, the GPL Version 2 or
8.36 - * to extend the choice of license to its licensees as provided above.
8.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
8.38 - * Version 2 license, then the option applies only if the new code is
8.39 - * made subject to such option by the copyright holder.
8.40 - *
8.41 - * Contributor(s):
8.42 - *
8.43 - * Portions Copyrighted 2008-2011 Sun Microsystems, Inc.
8.44 - */
8.45 -
8.46 -package org.netbeans.modules.jackpot30.ide.usages;
8.47 -
8.48 -import com.sun.source.tree.ClassTree;
8.49 -import com.sun.source.tree.IdentifierTree;
8.50 -import com.sun.source.tree.MemberSelectTree;
8.51 -import com.sun.source.tree.MethodTree;
8.52 -import com.sun.source.tree.NewClassTree;
8.53 -import com.sun.source.tree.ParameterizedTypeTree;
8.54 -import com.sun.source.tree.Tree;
8.55 -import com.sun.source.util.SourcePositions;
8.56 -import java.awt.Image;
8.57 -import java.io.IOException;
8.58 -import java.util.ArrayList;
8.59 -import java.util.Collection;
8.60 -import java.util.Collections;
8.61 -import java.util.Comparator;
8.62 -import java.util.HashMap;
8.63 -import java.util.HashSet;
8.64 -import java.util.LinkedList;
8.65 -import java.util.List;
8.66 -import java.util.Map;
8.67 -import java.util.Map.Entry;
8.68 -import java.util.Set;
8.69 -import java.util.concurrent.atomic.AtomicBoolean;
8.70 -import java.util.logging.Level;
8.71 -import java.util.logging.Logger;
8.72 -import javax.lang.model.element.Element;
8.73 -import javax.lang.model.element.ElementKind;
8.74 -import javax.lang.model.element.ExecutableElement;
8.75 -import javax.lang.model.element.Name;
8.76 -import javax.lang.model.element.TypeElement;
8.77 -import javax.lang.model.type.TypeKind;
8.78 -import javax.lang.model.type.TypeMirror;
8.79 -import javax.swing.Action;
8.80 -import org.netbeans.api.java.classpath.ClassPath;
8.81 -import org.netbeans.api.java.classpath.GlobalPathRegistry;
8.82 -import org.netbeans.api.java.source.CompilationController;
8.83 -import org.netbeans.api.java.source.CompilationInfo;
8.84 -import org.netbeans.api.java.source.ElementHandle;
8.85 -import org.netbeans.api.java.source.JavaSource;
8.86 -import org.netbeans.api.java.source.JavaSource.Phase;
8.87 -import org.netbeans.api.java.source.SourceUtils;
8.88 -import org.netbeans.api.java.source.Task;
8.89 -import org.netbeans.api.java.source.UiUtils;
8.90 -import org.netbeans.api.java.source.support.CancellableTreePathScanner;
8.91 -import org.netbeans.api.project.FileOwnerQuery;
8.92 -import org.netbeans.api.project.Project;
8.93 -import org.netbeans.api.project.ProjectUtils;
8.94 -import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
8.95 -import org.netbeans.spi.project.ui.LogicalViewProvider;
8.96 -import org.openide.actions.OpenAction;
8.97 -import org.openide.cookies.EditorCookie;
8.98 -import org.openide.cookies.LineCookie;
8.99 -import org.openide.cookies.OpenCookie;
8.100 -import org.openide.filesystems.FileObject;
8.101 -import org.openide.filesystems.FileUtil;
8.102 -import org.openide.loaders.DataObject;
8.103 -import org.openide.loaders.DataObjectNotFoundException;
8.104 -import org.openide.nodes.AbstractNode;
8.105 -import org.openide.nodes.ChildFactory;
8.106 -import org.openide.nodes.Children;
8.107 -import org.openide.nodes.FilterNode;
8.108 -import org.openide.nodes.Node;
8.109 -import org.openide.nodes.NodeOp;
8.110 -import org.openide.text.Line;
8.111 -import org.openide.util.Exceptions;
8.112 -import org.openide.util.ImageUtilities;
8.113 -import org.openide.util.NbBundle;
8.114 -import org.openide.util.lookup.AbstractLookup;
8.115 -import org.openide.util.lookup.InstanceContent;
8.116 -
8.117 -/**
8.118 - *
8.119 - * @author lahvac
8.120 - */
8.121 -public class Nodes {
8.122 -
8.123 - public static Node constructSemiLogicalView(Iterable<? extends FileObject> filesWithOccurrences, Map<RemoteIndex, List<String>> unmappable, ElementHandle<?> eh, Set<RemoteUsages.SearchOptions> options) {
8.124 - Map<Project, Collection<FileObject>> projects = new HashMap<Project, Collection<FileObject>>();
8.125 -
8.126 - for (FileObject file : filesWithOccurrences) {
8.127 - Project project = FileOwnerQuery.getOwner(file);
8.128 -
8.129 - if (project == null) {
8.130 - Logger.getLogger(Nodes.class.getName()).log(Level.WARNING, "Cannot find project for: {0}", FileUtil.getFileDisplayName(file));
8.131 - }
8.132 -
8.133 - Collection<FileObject> projectFiles = projects.get(project);
8.134 -
8.135 - if (projectFiles == null) {
8.136 - projects.put(project, projectFiles = new ArrayList<FileObject>());
8.137 - }
8.138 -
8.139 - projectFiles.add(file);
8.140 -
8.141 - //XXX: workarounding NbProject's Evaluator, which is too stupid to fire meaningfull property events, which leads to PackageView rebuilding inadvertedly itself due to virtual CONTAINERSHIP change:
8.142 - ClassPath.getClassPath(file, ClassPath.COMPILE).getRoots();
8.143 - }
8.144 -
8.145 - final Collection<FileObject> outsideProjects = projects.remove(null);
8.146 -
8.147 - List<Node> nodes = new ArrayList<Node>(projects.size());
8.148 -
8.149 - for (Project p : projects.keySet()) {
8.150 - nodes.add(constructSemiLogicalView(p, projects.get(p), eh, options));
8.151 - }
8.152 -
8.153 - Collections.sort(nodes, new Comparator<Node>() {
8.154 - @Override public int compare(Node o1, Node o2) {
8.155 - return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
8.156 - }
8.157 - });
8.158 -
8.159 - if (outsideProjects != null) {
8.160 - AbstractNode outsideProjectsNode = new AbstractNode(Children.create(new ChildFactory<FileObject>() {
8.161 - @Override protected boolean createKeys(List<FileObject> toPopulate) {
8.162 - toPopulate.addAll(outsideProjects);
8.163 - return true;
8.164 - }
8.165 - @Override protected Node createNodeForKey(FileObject file) {
8.166 - try {
8.167 - DataObject od = DataObject.find(file);
8.168 - return od.getNodeDelegate();
8.169 - } catch (DataObjectNotFoundException ex) {
8.170 - Exceptions.printStackTrace(ex);
8.171 - return null;
8.172 - }
8.173 - }
8.174 - }, true));
8.175 -
8.176 - outsideProjectsNode.setDisplayName("Occurrences outside locally recognized projects");
8.177 - nodes.add(outsideProjectsNode);
8.178 - }
8.179 -
8.180 - if (!unmappable.isEmpty()) {
8.181 - List<Node> localNodes = new ArrayList<Node>(unmappable.size());
8.182 -
8.183 - for (final Entry<RemoteIndex, List<String>> e : unmappable.entrySet()) {
8.184 - AbstractNode localNode = new AbstractNode(Children.create(new ChildFactory<String>() {
8.185 - @Override protected boolean createKeys(List<String> toPopulate) {
8.186 - Collections.sort(e.getValue());
8.187 - toPopulate.addAll(e.getValue());
8.188 - return true;
8.189 - }
8.190 - @Override protected Node createNodeForKey(String rel) {
8.191 - AbstractNode fileNode = new AbstractNode(Children.LEAF);
8.192 -
8.193 - fileNode.setDisplayName(rel);
8.194 - return fileNode;
8.195 - }
8.196 - }, true));
8.197 -
8.198 - localNode.setDisplayName("Index: " + e.getKey().remote.toExternalForm() + ", segment: " + e.getKey().remoteSegment);
8.199 - localNodes.add(localNode);
8.200 - }
8.201 -
8.202 - AbstractNode notExisting = new AbstractNode(new DirectChildren(localNodes));
8.203 -
8.204 - notExisting.setDisplayName("Occurrences in files that are not locally available");
8.205 - nodes.add(notExisting);
8.206 - }
8.207 -
8.208 - return new AbstractNode(new DirectChildren(nodes));
8.209 - }
8.210 -
8.211 - private static Node constructSemiLogicalView(final Project p, final Iterable<? extends FileObject> files, ElementHandle<?> eh, Set<RemoteUsages.SearchOptions> options) {
8.212 - final LogicalViewProvider lvp = p.getLookup().lookup(LogicalViewProvider.class);
8.213 - final Node view;
8.214 -
8.215 - if (lvp != null) {
8.216 - view = lvp.createLogicalView();
8.217 - } else {
8.218 - try {
8.219 - view = DataObject.find(p.getProjectDirectory()).getNodeDelegate();
8.220 - } catch (DataObjectNotFoundException ex) {
8.221 - Exceptions.printStackTrace(ex);
8.222 - return new AbstractNode(Children.LEAF);
8.223 - }
8.224 - }
8.225 -
8.226 - return new Wrapper(view, new ComputeNodes(files, view, lvp, p), eh, options);
8.227 - }
8.228 -
8.229 - private static Node locateChild(Node parent, LogicalViewProvider lvp, FileObject file) {
8.230 - if (lvp != null) {
8.231 - return lvp.findPath(parent, file);
8.232 - }
8.233 -
8.234 - throw new UnsupportedOperationException("Not done yet");
8.235 - }
8.236 -
8.237 - private static class Wrapper extends FilterNode {
8.238 -
8.239 - public Wrapper(Node orig, ComputeNodes fileNodes, ElementHandle<?> eh, Set<RemoteUsages.SearchOptions> options) {
8.240 - super(orig, new WrapperChildren(orig, fileNodes, eh, options));
8.241 - }
8.242 -
8.243 - @Override
8.244 - public Action[] getActions(boolean context) {
8.245 - return new Action[0];
8.246 - }
8.247 -
8.248 - }
8.249 -
8.250 - private static boolean isParent(Node parent, Node child) {
8.251 - if (NodeOp.isSon(parent, child)) {
8.252 - return true;
8.253 - }
8.254 -
8.255 - Node p = child.getParentNode();
8.256 -
8.257 - if (p == null) {
8.258 - return false;
8.259 - }
8.260 -
8.261 - return isParent(parent, p);
8.262 - }
8.263 -
8.264 - private static class WrapperChildren extends Children.Keys<Node> {
8.265 -
8.266 - private final Node orig;
8.267 - private final ComputeNodes fileNodes;
8.268 - private final ElementHandle<?> eh;
8.269 - private final Set<RemoteUsages.SearchOptions> options;
8.270 -
8.271 - public WrapperChildren(Node orig, ComputeNodes fileNodes, ElementHandle<?> eh, Set<RemoteUsages.SearchOptions> options) {
8.272 - this.orig = orig;
8.273 - this.fileNodes = fileNodes;
8.274 - this.eh = eh;
8.275 - this.options = options;
8.276 -
8.277 - }
8.278 -
8.279 - @Override
8.280 - protected void addNotify() {
8.281 - super.addNotify();
8.282 - doSetKeys();
8.283 - }
8.284 -
8.285 - private void doSetKeys() {
8.286 - Node[] nodes = orig.getChildren().getNodes(true);
8.287 - List<Node> toSet = new LinkedList<Node>();
8.288 -
8.289 - OUTER: for (Node n : nodes) {
8.290 - for (Node c : fileNodes.compute()) {
8.291 - if (n == c || isParent(n, c)) {
8.292 - toSet.add(n);
8.293 - continue OUTER;
8.294 - }
8.295 - }
8.296 - }
8.297 -
8.298 - setKeys(toSet);
8.299 - }
8.300 -
8.301 - @Override
8.302 - protected Node[] createNodes(Node key) {
8.303 - if (fileNodes.compute().contains(key)) {
8.304 - FileObject file = key.getLookup().lookup(FileObject.class);
8.305 - Children c = file != null ? Children.create(new UsagesChildren(file, eh, options), true) : Children.LEAF;
8.306 -
8.307 - return new Node[] {new FilterNode(key, c)}; //XXX
8.308 - }
8.309 - return new Node[] {new Wrapper(key, fileNodes, eh, options)};
8.310 - }
8.311 -
8.312 - }
8.313 -
8.314 - private static final class DirectChildren extends Children.Keys<Node> {
8.315 -
8.316 - public DirectChildren(Collection<Node> nodes) {
8.317 - setKeys(nodes);
8.318 - }
8.319 -
8.320 - @Override
8.321 - protected Node[] createNodes(Node key) {
8.322 - return new Node[] {key};
8.323 - }
8.324 - }
8.325 -
8.326 - private static Node noOccurrencesNode() {
8.327 - AbstractNode noOccurrences = new AbstractNode(Children.LEAF);
8.328 -
8.329 - noOccurrences.setDisplayName("No Occurrences Found");
8.330 -
8.331 - return noOccurrences;
8.332 - }
8.333 -
8.334 - private static final class UsagesChildren extends ChildFactory<Node> {
8.335 -
8.336 - private final FileObject file;
8.337 - private final ElementHandle<?> eh;
8.338 - private final Set<RemoteUsages.SearchOptions> options;
8.339 -
8.340 - public UsagesChildren(FileObject file, ElementHandle<?> eh, Set<RemoteUsages.SearchOptions> options) {
8.341 - this.file = file;
8.342 - this.eh = eh;
8.343 - this.options = options;
8.344 - }
8.345 -
8.346 - @Override
8.347 - protected boolean createKeys(final List<Node> toPopulate) {
8.348 - List<Node> result = new ArrayList<Node>();
8.349 -
8.350 - if (!computeOccurrences(file, eh, options, result)) {
8.351 - result.clear();
8.352 -
8.353 - ClassPath source = ClassPath.getClassPath(file, ClassPath.SOURCE);
8.354 -
8.355 - GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {source});
8.356 -
8.357 - try {
8.358 - SourceUtils.waitScanFinished();
8.359 - computeOccurrences(file, eh, options, result);
8.360 - } catch (InterruptedException ex) {
8.361 - Exceptions.printStackTrace(ex);
8.362 - } finally {
8.363 - GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, new ClassPath[] {source});
8.364 - }
8.365 - }
8.366 -
8.367 - toPopulate.addAll(result);
8.368 -
8.369 - if (toPopulate.isEmpty()) toPopulate.add(noOccurrencesNode());
8.370 -
8.371 - return true;
8.372 - }
8.373 -
8.374 - @Override
8.375 - protected Node createNodeForKey(Node key) {
8.376 - return key;
8.377 - }
8.378 -
8.379 - }
8.380 -
8.381 - static boolean computeOccurrences(FileObject file, final ElementHandle<?> eh, final Set<RemoteUsages.SearchOptions> options, final List<Node> toPopulate) {
8.382 - final boolean[] success = new boolean[] {true};
8.383 -
8.384 - try {
8.385 - JavaSource.forFileObject(file).runUserActionTask(new Task<CompilationController>() {
8.386 - @Override public void run(final CompilationController parameter) throws Exception {
8.387 - parameter.toPhase(Phase.RESOLVED);
8.388 -
8.389 - final Element toFind = eh.resolve(parameter);
8.390 -
8.391 - if (toFind == null) {
8.392 - return;
8.393 - }
8.394 -
8.395 - final AtomicBoolean stop = new AtomicBoolean();
8.396 -
8.397 - new CancellableTreePathScanner<Void, Void>(stop) {
8.398 - @Override public Void visitIdentifier(IdentifierTree node, Void p) {
8.399 - handleNode(node.getName(), getCurrentPath().getLeaf());
8.400 - return super.visitIdentifier(node, p);
8.401 - }
8.402 - @Override public Void visitMemberSelect(MemberSelectTree node, Void p) {
8.403 - handleNode(node.getIdentifier(), getCurrentPath().getLeaf());
8.404 - return super.visitMemberSelect(node, p);
8.405 - }
8.406 - @Override public Void visitNewClass(NewClassTree node, Void p) {
8.407 - Name simpleName = null;
8.408 - Tree name = node.getIdentifier();
8.409 -
8.410 - OUTER: while (true) {
8.411 - switch (name.getKind()) {
8.412 - case PARAMETERIZED_TYPE: name = ((ParameterizedTypeTree) name).getType(); break;
8.413 - case MEMBER_SELECT: simpleName = ((MemberSelectTree) name).getIdentifier(); break OUTER;
8.414 - case IDENTIFIER: simpleName = ((IdentifierTree) name).getName(); break OUTER;
8.415 - default: name = node; break OUTER;
8.416 - }
8.417 - }
8.418 -
8.419 - handleNode(simpleName, name);
8.420 - return super.visitNewClass(node, p);
8.421 - }
8.422 - private void handleNode(Name simpleName, Tree toHighlight) {
8.423 - if (!options.contains(RemoteUsages.SearchOptions.USAGES)) return;
8.424 - Element el = parameter.getTrees().getElement(getCurrentPath());
8.425 -
8.426 - if (el == null || el.asType().getKind() == TypeKind.ERROR) {
8.427 - if (toFind.getSimpleName().equals(simpleName)) {
8.428 - success[0] = false;
8.429 - stop.set(true);
8.430 - return; //TODO: correct? what about the second pass?
8.431 - }
8.432 - }
8.433 - if (Nodes.equals(parameter, toFind, el)) {
8.434 - toPopulate.add(new OccurrenceNode(parameter, toHighlight));
8.435 - }
8.436 - }
8.437 - @Override
8.438 - public Void visitMethod(MethodTree node, Void p) {
8.439 - if (options.contains(RemoteUsages.SearchOptions.SUB) && toFind.getKind() == ElementKind.METHOD) {
8.440 - boolean found = false;
8.441 - Element el = parameter.getTrees().getElement(getCurrentPath());
8.442 -
8.443 - if (el != null && el.getKind() == ElementKind.METHOD) {
8.444 - if (parameter.getElements().overrides((ExecutableElement) el, (ExecutableElement) toFind, (TypeElement) el.getEnclosingElement())) {
8.445 - toPopulate.add(new OccurrenceNode(parameter, node));
8.446 - found = true;
8.447 - }
8.448 - }
8.449 -
8.450 - if (!found && el != null && el.getSimpleName().contentEquals(toFind.getSimpleName())) {
8.451 - for (TypeMirror sup : superTypes((TypeElement) el.getEnclosingElement())) {
8.452 - if (sup.getKind() == TypeKind.ERROR) {
8.453 - success[0] = false;
8.454 - stop.set(true);
8.455 - return null; //TODO: correct? what about the second pass?
8.456 - }
8.457 - }
8.458 - }
8.459 - }
8.460 - return super.visitMethod(node, p);
8.461 - }
8.462 - @Override
8.463 - public Void visitClass(ClassTree node, Void p) {
8.464 - if (options.contains(RemoteUsages.SearchOptions.SUB) && (toFind.getKind().isClass() || toFind.getKind().isInterface())) {
8.465 - Element el = parameter.getTrees().getElement(getCurrentPath());
8.466 - boolean wasError = false;
8.467 -
8.468 - for (TypeMirror sup : superTypes((TypeElement) el)) {
8.469 - if (sup.getKind() == TypeKind.ERROR) {
8.470 - wasError = true;
8.471 - } else {
8.472 - if (toFind.equals(parameter.getTypes().asElement(sup))) {
8.473 - wasError = false;
8.474 - toPopulate.add(new OccurrenceNode(parameter, node));
8.475 - break;
8.476 - }
8.477 - }
8.478 - }
8.479 -
8.480 - if (wasError) {
8.481 - success[0] = false;
8.482 - stop.set(true);
8.483 - return null; //TODO: correct? what about the second pass?
8.484 - }
8.485 - }
8.486 -
8.487 - return super.visitClass(node, p);
8.488 - }
8.489 - private Set<TypeMirror> superTypes(TypeElement type) {
8.490 - Set<TypeMirror> result = new HashSet<TypeMirror>();
8.491 - List<TypeMirror> todo = new LinkedList<TypeMirror>();
8.492 -
8.493 - todo.add(type.asType());
8.494 -
8.495 - while (!todo.isEmpty()) {
8.496 - List<? extends TypeMirror> directSupertypes = parameter.getTypes().directSupertypes(todo.remove(0));
8.497 -
8.498 - todo.addAll(directSupertypes);
8.499 - result.addAll(directSupertypes);
8.500 - }
8.501 -
8.502 - return result;
8.503 - }
8.504 - }.scan(parameter.getCompilationUnit(), null);
8.505 - }
8.506 - }, true);
8.507 - } catch (IOException ex) {
8.508 - Exceptions.printStackTrace(ex);
8.509 - }
8.510 -
8.511 - return success[0];
8.512 - }
8.513 -
8.514 - private static boolean equals(CompilationInfo info, Element toFind, Element what) {
8.515 - if (toFind == what) return true;
8.516 - if (what == null) return false;
8.517 - if (toFind.getKind() != what.getKind()) return false;
8.518 - if (toFind.getKind() != ElementKind.METHOD) return false;
8.519 -
8.520 - return info.getElements().overrides((ExecutableElement) what, (ExecutableElement) toFind, (TypeElement) what.getEnclosingElement());
8.521 - }
8.522 -
8.523 - private static final class OccurrenceNode extends AbstractNode {
8.524 - private final FileObject file;
8.525 - private final int pos;
8.526 - private final String htmlDisplayName;
8.527 -
8.528 - public OccurrenceNode(CompilationInfo info, Tree occurrence) {
8.529 - this(info, occurrence, new InstanceContent());
8.530 - }
8.531 -
8.532 - private OccurrenceNode(CompilationInfo info, Tree occurrence, InstanceContent content) {
8.533 - super(Children.LEAF, new AbstractLookup(content));
8.534 -
8.535 - int[] span;
8.536 -
8.537 - switch (occurrence.getKind()) {
8.538 - case MEMBER_SELECT: span = info.getTreeUtilities().findNameSpan((MemberSelectTree) occurrence); break;
8.539 - case METHOD: span = info.getTreeUtilities().findNameSpan((MethodTree) occurrence); break;
8.540 - case CLASS: span = info.getTreeUtilities().findNameSpan((ClassTree) occurrence); break;
8.541 - default:
8.542 - SourcePositions sp = info.getTrees().getSourcePositions();
8.543 -
8.544 - span = new int[] {(int) sp.getStartPosition(info.getCompilationUnit(), occurrence),
8.545 - (int) sp.getEndPosition(info.getCompilationUnit(), occurrence)};
8.546 - break;
8.547 - }
8.548 -
8.549 - long startLine = info.getCompilationUnit().getLineMap().getLineNumber(span[0]);
8.550 - long startLineStart = info.getCompilationUnit().getLineMap().getStartPosition(startLine);
8.551 -
8.552 - String dn;
8.553 -
8.554 - try {
8.555 - DataObject od = DataObject.find(info.getFileObject());
8.556 - LineCookie lc = od.getLookup().lookup(LineCookie.class);
8.557 - Line l = lc.getLineSet().getCurrent((int) startLine - 1);
8.558 - od.getLookup().lookup(EditorCookie.class).openDocument();
8.559 - String line = l.getText();
8.560 - int endOnLine = (int) Math.min(line.length(), span[1] - startLineStart);
8.561 -
8.562 - dn = translate(line.substring(0, (int) (span[0] - startLineStart))) + "<b>" + translate(line.substring((int) (span[0] - startLineStart), endOnLine)) + "</b>" + translate(line.substring(endOnLine));
8.563 - } catch (IOException ex) {
8.564 - Exceptions.printStackTrace(ex);
8.565 - dn = "Occurrence";
8.566 - }
8.567 -
8.568 - this.htmlDisplayName = dn;
8.569 - this.file = info.getFileObject();
8.570 - this.pos = span[0];
8.571 -
8.572 - content.add(new OpenCookie() {
8.573 - @Override public void open() {
8.574 - UiUtils.open(file, pos);
8.575 - }
8.576 - });
8.577 - }
8.578 -
8.579 - @Override
8.580 - public String getHtmlDisplayName() {
8.581 - return htmlDisplayName;
8.582 - }
8.583 -
8.584 - @Override
8.585 - public Action[] getActions(boolean context) {
8.586 - return new Action[] {
8.587 - OpenAction.get(OpenAction.class)
8.588 - };
8.589 - }
8.590 -
8.591 - @Override
8.592 - public Action getPreferredAction() {
8.593 - return OpenAction.get(OpenAction.class);
8.594 - }
8.595 -
8.596 - }
8.597 -
8.598 - private static String[] c = new String[] {"&", "<", ">", "\n", "\""}; // NOI18N
8.599 - private static String[] tags = new String[] {"&", "<", ">", "<br>", """}; // NOI18N
8.600 -
8.601 - private static String translate(String input) {
8.602 - for (int cntr = 0; cntr < c.length; cntr++) {
8.603 - input = input.replaceAll(c[cntr], tags[cntr]);
8.604 - }
8.605 -
8.606 - return input;
8.607 - }
8.608 -
8.609 - private static class ComputeNodes {
8.610 -
8.611 - private final Iterable<? extends FileObject> files;
8.612 - private final Node view;
8.613 - private final LogicalViewProvider lvp;
8.614 - private final Project p;
8.615 -
8.616 - public ComputeNodes(Iterable<? extends FileObject> files, Node view, LogicalViewProvider lvp, Project p) {
8.617 - this.files = files;
8.618 - this.view = view;
8.619 - this.lvp = lvp;
8.620 - this.p = p;
8.621 - }
8.622 -
8.623 - private Collection<Node> result;
8.624 -
8.625 - public synchronized Collection<Node> compute() {
8.626 - if (result != null) return result;
8.627 -
8.628 - Collection<Node> fileNodes = new ArrayList<Node>();
8.629 -
8.630 - for (FileObject file : files) {
8.631 - Node foundChild = locateChild(view, lvp, file);
8.632 -
8.633 - if (foundChild == null) {
8.634 - foundChild = new AbstractNode(Children.LEAF) {
8.635 - @Override
8.636 - public Image getIcon(int type) {
8.637 - return ImageUtilities.icon2Image(ProjectUtils.getInformation(p).getIcon());
8.638 - }
8.639 - @Override
8.640 - public Image getOpenedIcon(int type) {
8.641 - return getIcon(type);
8.642 - }
8.643 - @Override
8.644 - public String getHtmlDisplayName() {
8.645 - return view.getHtmlDisplayName() != null ? NbBundle.getMessage(Nodes.class, "ERR_ProjectNotSupported", view.getHtmlDisplayName()) : null;
8.646 - }
8.647 - @Override
8.648 - public String getDisplayName() {
8.649 - return NbBundle.getMessage(Nodes.class, "ERR_ProjectNotSupported", view.getDisplayName());
8.650 - }
8.651 - };
8.652 - }
8.653 -
8.654 - fileNodes.add(foundChild);
8.655 - }
8.656 -
8.657 - return result = fileNodes;
8.658 - }
8.659 - }
8.660 -}
9.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java Fri Aug 10 22:46:58 2012 +0200
9.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java Wed Aug 15 14:33:00 2012 +0200
9.3 @@ -41,22 +41,24 @@
9.4 */
9.5 package org.netbeans.modules.jackpot30.ide.usages;
9.6
9.7 +import com.sun.source.tree.ClassTree;
9.8 +import com.sun.source.tree.IdentifierTree;
9.9 +import com.sun.source.tree.MemberSelectTree;
9.10 +import com.sun.source.tree.MethodTree;
9.11 +import com.sun.source.tree.NewClassTree;
9.12 +import com.sun.source.tree.ParameterizedTypeTree;
9.13 +import com.sun.source.tree.Tree;
9.14 import com.sun.source.util.TreePath;
9.15 -import java.awt.BorderLayout;
9.16 -import java.awt.CardLayout;
9.17 -import java.awt.Dialog;
9.18 -import java.awt.Insets;
9.19 -import java.awt.event.ActionEvent;
9.20 -import java.awt.event.ActionListener;
9.21 import java.io.IOException;
9.22 import java.net.URI;
9.23 import java.net.URISyntaxException;
9.24 import java.util.ArrayList;
9.25 import java.util.Collection;
9.26 -import java.util.EnumSet;
9.27 +import java.util.Collections;
9.28 import java.util.HashMap;
9.29 import java.util.HashSet;
9.30 import java.util.LinkedHashMap;
9.31 +import java.util.LinkedList;
9.32 import java.util.List;
9.33 import java.util.Map;
9.34 import java.util.Map.Entry;
9.35 @@ -65,254 +67,93 @@
9.36 import javax.lang.model.element.Element;
9.37 import javax.lang.model.element.ElementKind;
9.38 import javax.lang.model.element.ExecutableElement;
9.39 -import javax.swing.JButton;
9.40 -import javax.swing.JLabel;
9.41 -import javax.swing.JPanel;
9.42 -import javax.swing.SwingUtilities;
9.43 -import javax.swing.border.EmptyBorder;
9.44 -import javax.swing.text.JTextComponent;
9.45 +import javax.lang.model.element.Name;
9.46 +import javax.lang.model.element.TypeElement;
9.47 +import javax.lang.model.type.TypeKind;
9.48 +import javax.lang.model.type.TypeMirror;
9.49 +import javax.swing.Icon;
9.50 import org.codeviation.pojson.Pojson;
9.51 -import org.netbeans.api.editor.EditorRegistry;
9.52 import org.netbeans.api.java.source.CompilationController;
9.53 import org.netbeans.api.java.source.CompilationInfo;
9.54 import org.netbeans.api.java.source.ElementHandle;
9.55 import org.netbeans.api.java.source.JavaSource;
9.56 +import org.netbeans.api.java.source.JavaSource.Phase;
9.57 import org.netbeans.api.java.source.Task;
9.58 -import org.netbeans.api.java.source.ui.ElementHeaders;
9.59 -import org.netbeans.api.java.source.ui.ScanDialog;
9.60 -import org.netbeans.modules.editor.NbEditorUtilities;
9.61 +import org.netbeans.api.java.source.support.CancellableTreePathScanner;
9.62 import org.netbeans.modules.jackpot30.common.api.JavaUtils;
9.63 import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
9.64 import org.netbeans.modules.jackpot30.remoting.api.WebUtilities;
9.65 -import org.openide.DialogDescriptor;
9.66 -import org.openide.DialogDisplayer;
9.67 -import org.openide.NotifyDescriptor;
9.68 -import org.openide.NotifyDescriptor.Message;
9.69 -import org.openide.awt.ActionID;
9.70 -import org.openide.awt.ActionReference;
9.71 -import org.openide.awt.ActionReferences;
9.72 -import org.openide.awt.ActionRegistration;
9.73 +import org.netbeans.modules.refactoring.java.WhereUsedElement;
9.74 +import org.netbeans.modules.refactoring.java.ui.tree.ElementGrip;
9.75 +import org.netbeans.modules.refactoring.java.ui.tree.RefactoringTreeElement;
9.76 +import org.netbeans.modules.refactoring.spi.ui.TreeElement;
9.77 +import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory;
9.78 import org.openide.filesystems.FileObject;
9.79 import org.openide.filesystems.URLMapper;
9.80 import org.openide.nodes.Node;
9.81 import org.openide.util.Cancellable;
9.82 import org.openide.util.Exceptions;
9.83 -import org.openide.util.NbBundle.Messages;
9.84 -import org.openide.util.RequestProcessor;
9.85
9.86 -@ActionID(category = "Refactoring",
9.87 -id = "org.netbeans.modules.jackpot30.ide.usages.RemoteUsages")
9.88 -@ActionRegistration(displayName = "#CTL_RemoteUsages")
9.89 -@ActionReferences({
9.90 - @ActionReference(path = "Menu/Edit", position = 2250)
9.91 -})
9.92 -@Messages("CTL_RemoteUsages=Find Remote Usages...")
9.93 -public final class RemoteUsages implements ActionListener {
9.94 +public final class RemoteUsages {
9.95
9.96 - private final RequestProcessor WORKER = new RequestProcessor(RemoteUsages.class.getName(), 1, false, false);
9.97 -
9.98 - public void actionPerformed(ActionEvent e) {
9.99 - JTextComponent comp = EditorRegistry.lastFocusedComponent(); //XXX
9.100 + //XXX: handle unmappable result!
9.101 + public static List<FileObject> findUsages(ElementHandle<?> toSearch, Set<SearchOptions> options, AtomicBoolean cancel) {
9.102 + try {
9.103 + final String serialized = JavaUtils.serialize(toSearch);
9.104
9.105 - if (comp == null) return;
9.106 + Set<FileObject> resultSet = new HashSet<FileObject>();
9.107 + List<FileObject> result = new ArrayList<FileObject>();
9.108 + Map<RemoteIndex, List<String>> unmappable = new HashMap<RemoteIndex, List<String>>();
9.109
9.110 - final FileObject file = NbEditorUtilities.getFileObject(comp.getDocument());
9.111 - final int pos = comp.getCaretPosition();
9.112 - final ElementDescription element = findElement(file, pos);
9.113 + for (RemoteIndex idx : RemoteIndex.loadIndices()) {
9.114 + FileObject localFolder = URLMapper.findFileObject(idx.getLocalFolder());
9.115
9.116 - if (element == null) {
9.117 - Message message = new NotifyDescriptor.Message("Cannot find usages of this element", NotifyDescriptor.Message.ERROR_MESSAGE);
9.118 - DialogDisplayer.getDefault().notifyLater(message);
9.119 - return ;
9.120 - }
9.121 + if (options.contains(SearchOptions.USAGES)) {
9.122 + URI resolved = new URI(idx.remote.toExternalForm() + "/usages/search?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&signatures=" + WebUtilities.escapeForQuery(serialized));
9.123 + Collection<? extends String> response = WebUtilities.requestStringArrayResponse(resolved, cancel);
9.124
9.125 - final Set<SearchOptions> options = EnumSet.noneOf(SearchOptions.class);
9.126 - final JButton okButton = new JButton("OK");
9.127 - JButton cancelButton = new JButton("Cancel");
9.128 - JPanel dialogContent = constructDialog(element, options, okButton);
9.129 + if (cancel.get()) return Collections.emptyList();
9.130 + if (response == null) continue;
9.131
9.132 - DialogDescriptor dd = new DialogDescriptor(dialogContent, "Remote Find Usages", true, new Object[] {okButton, cancelButton}, okButton, DialogDescriptor.DEFAULT_ALIGN, null, new ActionListener() {
9.133 - @Override public void actionPerformed(ActionEvent e) { }
9.134 - });
9.135 - final Dialog d = DialogDisplayer.getDefault().createDialog(dd);
9.136 + for (String path : response) {
9.137 + if (path.trim().isEmpty()) continue;
9.138 + FileObject file = localFolder.getFileObject(path);
9.139
9.140 - final AtomicBoolean cancel = new AtomicBoolean();
9.141 + if (file != null) {
9.142 + if (resultSet.add(file)) {
9.143 + result.add(file);
9.144 + }
9.145 + } else {
9.146 + List<String> um = unmappable.get(idx);
9.147
9.148 - okButton.addActionListener(new ActionListener() {
9.149 - @Override public void actionPerformed(ActionEvent e) {
9.150 - okButton.setEnabled(false);
9.151 - WORKER.post(new FindUsagesWorker(options.contains(SearchOptions.FROM_BASE) ? element.superMethod : element.element, options, d, cancel));
9.152 - }
9.153 - });
9.154 + if (um == null) {
9.155 + unmappable.put(idx, um = new ArrayList<String>());
9.156 + }
9.157
9.158 - cancelButton.addActionListener(new ActionListener() {
9.159 - @Override public void actionPerformed(ActionEvent e) {
9.160 - cancel.set(true);
9.161 - d.setVisible(false);
9.162 - }
9.163 - });
9.164 -
9.165 - d.setVisible(true);
9.166 - }
9.167 -
9.168 - private static ElementDescription findElement(final FileObject file, final int pos) {
9.169 - final ElementDescription[] handle = new ElementDescription[1];
9.170 -
9.171 - final JavaSource js = JavaSource.forFileObject(file);
9.172 -
9.173 - ScanDialog.runWhenScanFinished(new Runnable() {
9.174 - @Override public void run() {
9.175 - try {
9.176 - js.runUserActionTask(new Task<CompilationController>() {
9.177 - @Override public void run(CompilationController parameter) throws Exception {
9.178 - parameter.toPhase(JavaSource.Phase.RESOLVED);
9.179 -
9.180 - TreePath tp = parameter.getTreeUtilities().pathFor(pos);
9.181 - Element el = parameter.getTrees().getElement(tp);
9.182 -
9.183 - if (el != null && JavaUtils.SUPPORTED_KINDS.contains(el.getKind())) {
9.184 - handle[0] = new ElementDescription(parameter, el);
9.185 - }
9.186 + um.add(path);
9.187 }
9.188 - }, true);
9.189 - } catch (IOException ex) {
9.190 - Exceptions.printStackTrace(ex);
9.191 - }
9.192 - }
9.193 -
9.194 - }, "Find Remote Usages");
9.195 -
9.196 - return handle[0];
9.197 - }
9.198 -
9.199 - private JPanel constructDialog(ElementDescription toSearch, Set<SearchOptions> options, JButton ok) {
9.200 - JPanel searchKind;
9.201 -
9.202 - switch (toSearch.element.getKind()) {
9.203 - case METHOD: searchKind = new MethodOptions(toSearch, options); break;
9.204 - case CLASS:
9.205 - case INTERFACE:
9.206 - case ANNOTATION_TYPE: searchKind = new ClassOptions(options); break;
9.207 - default:
9.208 - options.add(RemoteUsages.SearchOptions.USAGES);
9.209 - searchKind = new JPanel();
9.210 - break;
9.211 - }
9.212 -
9.213 - final JPanel progress = new JPanel();
9.214 -
9.215 - progress.setLayout(new CardLayout());
9.216 - progress.add(new JPanel(), "hide");
9.217 - progress.add(new JLabel("Querying remote server(s), please wait"), "show");
9.218 -
9.219 - ok.addActionListener(new ActionListener() {
9.220 - @Override public void actionPerformed(ActionEvent e) {
9.221 - ((CardLayout) progress.getLayout()).show(progress, "show");
9.222 - }
9.223 - });
9.224 -
9.225 - JPanel result = new JPanel();
9.226 -
9.227 - result.setLayout(new BorderLayout());
9.228 - result.setBorder(new EmptyBorder(new Insets(12, 12, 12, 12)));
9.229 -
9.230 - result.add(new JLabel(toSearch.displayName), BorderLayout.NORTH);
9.231 - result.add(searchKind, BorderLayout.CENTER);
9.232 - result.add(progress, BorderLayout.SOUTH);
9.233 -
9.234 - return result;
9.235 - }
9.236 -
9.237 - public static final class ElementDescription {
9.238 - public final ElementHandle<?> element;
9.239 - public final String displayName;
9.240 - public final ElementHandle<?> superMethod;
9.241 - public final String superMethodDisplayName;
9.242 -
9.243 - public ElementDescription(CompilationInfo info, Element el) {
9.244 - this.displayName = displayNameForElement(el, info);
9.245 -
9.246 - if (el.getKind() == ElementKind.METHOD) {
9.247 - ExecutableElement base = (ExecutableElement) el;
9.248 -
9.249 - while (true) {
9.250 - ExecutableElement current = info.getElementUtilities().getOverriddenMethod(base);
9.251 -
9.252 - if (current == null) break;
9.253 -
9.254 - base = current;
9.255 + }
9.256 }
9.257
9.258 - if (base != el) {
9.259 - superMethod = ElementHandle.create(base);
9.260 - superMethodDisplayName = displayNameForElement(base, info);
9.261 - } else {
9.262 - superMethod = null;
9.263 - superMethodDisplayName = null;
9.264 - }
9.265 - } else {
9.266 - superMethod = null;
9.267 - superMethodDisplayName = null;
9.268 - }
9.269 + if (options.contains(SearchOptions.SUB)) {
9.270 + URI resolved;
9.271 + if (toSearch.getKind() == ElementKind.METHOD) {
9.272 + resolved = new URI(idx.remote.toExternalForm() + "/implements/search?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&method=" + WebUtilities.escapeForQuery(serialized));
9.273 + } else {
9.274 + resolved = new URI(idx.remote.toExternalForm() + "/implements/search?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&type=" + WebUtilities.escapeForQuery(toSearch.getBinaryName()));
9.275 + }
9.276
9.277 - element = ElementHandle.create(el);
9.278 - }
9.279 + String response = WebUtilities.requestStringResponse(resolved, cancel);
9.280
9.281 - private String displayNameForElement(Element el, CompilationInfo info) throws UnsupportedOperationException {
9.282 - switch (el.getKind()) {
9.283 - case METHOD:
9.284 - return "<html>Method <b>" + ElementHeaders.getHeader(el, info, ElementHeaders.NAME + ElementHeaders.PARAMETERS) + "</b> of class <b>" + ElementHeaders.getHeader(el.getEnclosingElement(), info, ElementHeaders.NAME);
9.285 - case CONSTRUCTOR:
9.286 - return "<html>Constructor <b>" + ElementHeaders.getHeader(el, info, ElementHeaders.NAME + ElementHeaders.PARAMETERS) + "</b> of class <b>" + ElementHeaders.getHeader(el.getEnclosingElement(), info, ElementHeaders.NAME);
9.287 - case CLASS:
9.288 - case INTERFACE:
9.289 - case ENUM:
9.290 - case ANNOTATION_TYPE:
9.291 - return "<html>Type <b>" + ElementHeaders.getHeader(el, info, ElementHeaders.NAME);
9.292 - case FIELD:
9.293 - case ENUM_CONSTANT:
9.294 - return "<html>Field <b>" + ElementHeaders.getHeader(el, info, ElementHeaders.NAME) + " of class " + ElementHeaders.getHeader(el.getEnclosingElement(), info, ElementHeaders.NAME);
9.295 - default:
9.296 - throw new UnsupportedOperationException();
9.297 - }
9.298 - }
9.299 + if (cancel.get()) return Collections.emptyList();
9.300 + if (response == null) continue;
9.301
9.302 - }
9.303 + //XXX:
9.304 + Map<String, List<Map<String, String>>> formattedResponse = Pojson.load(LinkedHashMap.class, response);
9.305
9.306 - private static class FindUsagesWorker implements Runnable, Cancellable {
9.307 -
9.308 - private final ElementHandle<?> toSearch;
9.309 - private final Set<SearchOptions> options;
9.310 - private final Dialog d;
9.311 - private final AtomicBoolean cancel;
9.312 -
9.313 - public FindUsagesWorker(ElementHandle<?> toSearch, Set<SearchOptions> options, Dialog d, AtomicBoolean cancel) {
9.314 - this.toSearch = toSearch;
9.315 - this.options = options;
9.316 - this.d = d;
9.317 - this.cancel = cancel;
9.318 - }
9.319 -
9.320 - @Override public void run() {
9.321 - try {
9.322 - final String serialized = JavaUtils.serialize(toSearch);
9.323 -
9.324 - Set<FileObject> resultSet = new HashSet<FileObject>();
9.325 - List<FileObject> result = new ArrayList<FileObject>();
9.326 - Map<RemoteIndex, List<String>> unmappable = new HashMap<RemoteIndex, List<String>>();
9.327 -
9.328 - for (RemoteIndex idx : RemoteIndex.loadIndices()) {
9.329 - FileObject localFolder = URLMapper.findFileObject(idx.getLocalFolder());
9.330 -
9.331 - if (options.contains(SearchOptions.USAGES)) {
9.332 - URI resolved = new URI(idx.remote.toExternalForm() + "/usages/search?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&signatures=" + WebUtilities.escapeForQuery(serialized));
9.333 - Collection<? extends String> response = WebUtilities.requestStringArrayResponse(resolved, cancel);
9.334 -
9.335 - if (cancel.get()) return;
9.336 - if (response == null) continue;
9.337 -
9.338 - for (String path : response) {
9.339 - if (path.trim().isEmpty()) continue;
9.340 + for (Entry<String, List<Map<String, String>>> e : formattedResponse.entrySet()) {
9.341 + for (Map<String, String> p : e.getValue()) {
9.342 + String path = p.get("file");
9.343 FileObject file = localFolder.getFileObject(path);
9.344
9.345 if (file != null) {
9.346 @@ -330,70 +171,15 @@
9.347 }
9.348 }
9.349 }
9.350 + }
9.351 + }
9.352
9.353 - if (options.contains(SearchOptions.SUB)) {
9.354 - URI resolved;
9.355 - if (toSearch.getKind() == ElementKind.METHOD) {
9.356 - resolved = new URI(idx.remote.toExternalForm() + "/implements/search?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&method=" + WebUtilities.escapeForQuery(serialized));
9.357 - } else {
9.358 - resolved = new URI(idx.remote.toExternalForm() + "/implements/search?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&type=" + WebUtilities.escapeForQuery(toSearch.getBinaryName()));
9.359 - }
9.360 -
9.361 - String response = WebUtilities.requestStringResponse(resolved, cancel);
9.362 -
9.363 - if (cancel.get()) return;
9.364 - if (response == null) continue;
9.365 -
9.366 - //XXX:
9.367 - Map<String, List<Map<String, String>>> formattedResponse = Pojson.load(LinkedHashMap.class, response);
9.368 -
9.369 - for (Entry<String, List<Map<String, String>>> e : formattedResponse.entrySet()) {
9.370 - for (Map<String, String> p : e.getValue()) {
9.371 - String path = p.get("file");
9.372 - FileObject file = localFolder.getFileObject(path);
9.373 -
9.374 - if (file != null) {
9.375 - if (resultSet.add(file)) {
9.376 - result.add(file);
9.377 - }
9.378 - } else {
9.379 - List<String> um = unmappable.get(idx);
9.380 -
9.381 - if (um == null) {
9.382 - unmappable.put(idx, um = new ArrayList<String>());
9.383 - }
9.384 -
9.385 - um.add(path);
9.386 - }
9.387 - }
9.388 - }
9.389 - }
9.390 - }
9.391 -
9.392 - final Node view = Nodes.constructSemiLogicalView(result, unmappable, toSearch, options);
9.393 -
9.394 - if (!cancel.get()) {
9.395 - SwingUtilities.invokeLater(new Runnable() {
9.396 - @Override public void run() {
9.397 - RemoteUsagesWindowTopComponent.openFor(view);
9.398 - }
9.399 - });
9.400 - }
9.401 - } catch (URISyntaxException ex) {
9.402 - Exceptions.printStackTrace(ex);
9.403 - } finally {
9.404 - cancel.set(true);
9.405 - SwingUtilities.invokeLater(new Runnable() {
9.406 - @Override public void run() {
9.407 - d.setVisible(false);
9.408 - }
9.409 - });
9.410 - }
9.411 - }
9.412 -
9.413 - @Override public boolean cancel() {
9.414 + return result;
9.415 + } catch (URISyntaxException ex) {
9.416 + Exceptions.printStackTrace(ex);
9.417 + return Collections.emptyList();
9.418 + } finally {
9.419 cancel.set(true);
9.420 - return true;
9.421 }
9.422 }
9.423
9.424 @@ -402,4 +188,178 @@
9.425 SUB,
9.426 FROM_BASE;
9.427 }
9.428 +
9.429 + public static boolean computeOccurrences(FileObject file, final ElementHandle<?> eh, final Set<RemoteUsages.SearchOptions> options, final TreeElement parent, final List<TreeElement> toPopulate) {
9.430 + final boolean[] success = new boolean[] {true};
9.431 +
9.432 + try {
9.433 + JavaSource.forFileObject(file).runUserActionTask(new Task<CompilationController>() {
9.434 + @Override public void run(final CompilationController parameter) throws Exception {
9.435 + parameter.toPhase(Phase.RESOLVED);
9.436 +
9.437 + final Element toFind = eh.resolve(parameter);
9.438 +
9.439 + if (toFind == null) {
9.440 + return;
9.441 + }
9.442 +
9.443 + final AtomicBoolean stop = new AtomicBoolean();
9.444 +
9.445 + new CancellableTreePathScanner<Void, Void>(stop) {
9.446 + @Override public Void visitIdentifier(IdentifierTree node, Void p) {
9.447 + handleNode(node.getName(), getCurrentPath());
9.448 + return super.visitIdentifier(node, p);
9.449 + }
9.450 + @Override public Void visitMemberSelect(MemberSelectTree node, Void p) {
9.451 + handleNode(node.getIdentifier(), getCurrentPath());
9.452 + return super.visitMemberSelect(node, p);
9.453 + }
9.454 + @Override public Void visitNewClass(NewClassTree node, Void p) {
9.455 + Name simpleName = null;
9.456 + TreePath name = new TreePath(getCurrentPath(), node.getIdentifier());
9.457 +
9.458 + OUTER: while (true) {
9.459 + switch (name.getLeaf().getKind()) {
9.460 + case PARAMETERIZED_TYPE: name = new TreePath(name, ((ParameterizedTypeTree) name.getLeaf()).getType()); break;
9.461 + case MEMBER_SELECT: simpleName = ((MemberSelectTree) name).getIdentifier(); break OUTER;
9.462 + case IDENTIFIER: simpleName = ((IdentifierTree) name.getLeaf()).getName(); break OUTER;
9.463 + default: name = getCurrentPath(); break OUTER;
9.464 + }
9.465 + }
9.466 +
9.467 + handleNode(simpleName, name);
9.468 + return super.visitNewClass(node, p);
9.469 + }
9.470 + private void handleNode(Name simpleName, TreePath toHighlight) {
9.471 + if (!options.contains(RemoteUsages.SearchOptions.USAGES)) return;
9.472 + Element el = parameter.getTrees().getElement(getCurrentPath());
9.473 +
9.474 + if (el == null || el.asType().getKind() == TypeKind.ERROR) {
9.475 + if (toFind.getSimpleName().equals(simpleName)) {
9.476 + success[0] = false;
9.477 + stop.set(true);
9.478 + return; //TODO: correct? what about the second pass?
9.479 + }
9.480 + }
9.481 + if (RemoteUsages.equals(parameter, toFind, el)) {
9.482 + toPopulate.add(new UsageTreeElementImpl(parameter, toHighlight, parent));
9.483 + }
9.484 + }
9.485 + @Override
9.486 + public Void visitMethod(MethodTree node, Void p) {
9.487 + if (options.contains(RemoteUsages.SearchOptions.SUB) && toFind.getKind() == ElementKind.METHOD) {
9.488 + boolean found = false;
9.489 + Element el = parameter.getTrees().getElement(getCurrentPath());
9.490 +
9.491 + if (el != null && el.getKind() == ElementKind.METHOD) {
9.492 + if (parameter.getElements().overrides((ExecutableElement) el, (ExecutableElement) toFind, (TypeElement) el.getEnclosingElement())) {
9.493 + toPopulate.add(new UsageTreeElementImpl(parameter, getCurrentPath(), parent));
9.494 + found = true;
9.495 + }
9.496 + }
9.497 +
9.498 + if (!found && el != null && el.getSimpleName().contentEquals(toFind.getSimpleName())) {
9.499 + for (TypeMirror sup : superTypes((TypeElement) el.getEnclosingElement())) {
9.500 + if (sup.getKind() == TypeKind.ERROR) {
9.501 + success[0] = false;
9.502 + stop.set(true);
9.503 + return null; //TODO: correct? what about the second pass?
9.504 + }
9.505 + }
9.506 + }
9.507 + }
9.508 + return super.visitMethod(node, p);
9.509 + }
9.510 + @Override
9.511 + public Void visitClass(ClassTree node, Void p) {
9.512 + if (options.contains(RemoteUsages.SearchOptions.SUB) && (toFind.getKind().isClass() || toFind.getKind().isInterface())) {
9.513 + Element el = parameter.getTrees().getElement(getCurrentPath());
9.514 + boolean wasError = false;
9.515 +
9.516 + for (TypeMirror sup : superTypes((TypeElement) el)) {
9.517 + if (sup.getKind() == TypeKind.ERROR) {
9.518 + wasError = true;
9.519 + } else {
9.520 + if (toFind.equals(parameter.getTypes().asElement(sup))) {
9.521 + wasError = false;
9.522 + toPopulate.add(new UsageTreeElementImpl(parameter, getCurrentPath(), parent));
9.523 + break;
9.524 + }
9.525 + }
9.526 + }
9.527 +
9.528 + if (wasError) {
9.529 + success[0] = false;
9.530 + stop.set(true);
9.531 + return null; //TODO: correct? what about the second pass?
9.532 + }
9.533 + }
9.534 +
9.535 + return super.visitClass(node, p);
9.536 + }
9.537 + private Set<TypeMirror> superTypes(TypeElement type) {
9.538 + Set<TypeMirror> result = new HashSet<TypeMirror>();
9.539 + List<TypeMirror> todo = new LinkedList<TypeMirror>();
9.540 +
9.541 + todo.add(type.asType());
9.542 +
9.543 + while (!todo.isEmpty()) {
9.544 + List<? extends TypeMirror> directSupertypes = parameter.getTypes().directSupertypes(todo.remove(0));
9.545 +
9.546 + todo.addAll(directSupertypes);
9.547 + result.addAll(directSupertypes);
9.548 + }
9.549 +
9.550 + return result;
9.551 + }
9.552 + }.scan(parameter.getCompilationUnit(), null);
9.553 + }
9.554 + }, true);
9.555 + } catch (IOException ex) {
9.556 + Exceptions.printStackTrace(ex);
9.557 + }
9.558 +
9.559 + return success[0];
9.560 + }
9.561 +
9.562 + private static boolean equals(CompilationInfo info, Element toFind, Element what) {
9.563 + if (toFind == what) return true;
9.564 + if (what == null) return false;
9.565 + if (toFind.getKind() != what.getKind()) return false;
9.566 + if (toFind.getKind() != ElementKind.METHOD) return false;
9.567 +
9.568 + return info.getElements().overrides((ExecutableElement) what, (ExecutableElement) toFind, (TypeElement) what.getEnclosingElement());
9.569 + }
9.570 +
9.571 + private static final class UsageTreeElementImpl implements TreeElement {
9.572 +
9.573 + private final WhereUsedElement delegate;
9.574 + private final TreeElement parent;
9.575 +
9.576 + public UsageTreeElementImpl(CompilationInfo info, TreePath toHighlight, TreeElement parent) {
9.577 + delegate = WhereUsedElement.create(info, toHighlight, false);
9.578 + this.parent = parent;
9.579 + }
9.580 +
9.581 + @Override
9.582 + public TreeElement getParent(boolean isLogical) {
9.583 + return parent;
9.584 + }
9.585 +
9.586 + @Override
9.587 + public Icon getIcon() {
9.588 + return delegate.getLookup().lookup(Icon.class);
9.589 + }
9.590 +
9.591 + @Override
9.592 + public String getText(boolean isLogical) {
9.593 + return delegate.getDisplayText();
9.594 + }
9.595 +
9.596 + @Override
9.597 + public Object getUserObject() {
9.598 + return delegate;
9.599 + }
9.600 +
9.601 + }
9.602 }
10.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsagesWindowTopComponent.form Fri Aug 10 22:46:58 2012 +0200
10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
10.3 @@ -1,17 +0,0 @@
10.4 -<?xml version="1.1" encoding="UTF-8" ?>
10.5 -
10.6 -<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
10.7 - <AuxValues>
10.8 - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
10.9 - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
10.10 - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
10.11 - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
10.12 - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
10.13 - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
10.14 - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
10.15 - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
10.16 - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
10.17 - </AuxValues>
10.18 -
10.19 - <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
10.20 -</Form>
11.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsagesWindowTopComponent.java Fri Aug 10 22:46:58 2012 +0200
11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
11.3 @@ -1,147 +0,0 @@
11.4 -/*
11.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
11.6 - *
11.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
11.8 - *
11.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
11.10 - * Other names may be trademarks of their respective owners.
11.11 - *
11.12 - * The contents of this file are subject to the terms of either the GNU
11.13 - * General Public License Version 2 only ("GPL") or the Common
11.14 - * Development and Distribution License("CDDL") (collectively, the
11.15 - * "License"). You may not use this file except in compliance with the
11.16 - * License. You can obtain a copy of the License at
11.17 - * http://www.netbeans.org/cddl-gplv2.html
11.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
11.19 - * specific language governing permissions and limitations under the
11.20 - * License. When distributing the software, include this License Header
11.21 - * Notice in each file and include the License file at
11.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
11.23 - * particular file as subject to the "Classpath" exception as provided
11.24 - * by Oracle in the GPL Version 2 section of the License file that
11.25 - * accompanied this code. If applicable, add the following below the
11.26 - * License Header, with the fields enclosed by brackets [] replaced by
11.27 - * your own identifying information:
11.28 - * "Portions Copyrighted [year] [name of copyright owner]"
11.29 - *
11.30 - * If you wish your version of this file to be governed by only the CDDL
11.31 - * or only the GPL Version 2, indicate your decision by adding
11.32 - * "[Contributor] elects to include this software in this distribution
11.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
11.34 - * single choice of license, a recipient has the option to distribute
11.35 - * your version of this file under either the CDDL, the GPL Version 2 or
11.36 - * to extend the choice of license to its licensees as provided above.
11.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
11.38 - * Version 2 license, then the option applies only if the new code is
11.39 - * made subject to such option by the copyright holder.
11.40 - *
11.41 - * Contributor(s):
11.42 - *
11.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
11.44 - */
11.45 -package org.netbeans.modules.jackpot30.ide.usages;
11.46 -
11.47 -import java.awt.BorderLayout;
11.48 -import org.openide.util.NbBundle;
11.49 -import org.openide.windows.Mode;
11.50 -import org.openide.windows.TopComponent;
11.51 -import org.netbeans.api.settings.ConvertAsProperties;
11.52 -import org.openide.awt.ActionID;
11.53 -import org.openide.awt.ActionReference;
11.54 -import org.openide.explorer.ExplorerManager;
11.55 -import org.openide.explorer.view.BeanTreeView;
11.56 -import org.openide.nodes.Node;
11.57 -import org.openide.windows.WindowManager;
11.58 -
11.59 -/**
11.60 - * Top component which displays something.
11.61 - */
11.62 -@ConvertAsProperties(dtd = "-//org.netbeans.modules.jackpot30.ide.usages//RemoteUsagesWindow//EN",
11.63 -autostore = false)
11.64 -@TopComponent.Description(preferredID = "RemoteUsagesWindowTopComponent",
11.65 -//iconBase="SET/PATH/TO/ICON/HERE",
11.66 -persistenceType = TopComponent.PERSISTENCE_ALWAYS)
11.67 -@TopComponent.Registration(mode = "output", openAtStartup = false)
11.68 -@ActionID(category = "Window", id = "org.netbeans.modules.jackpot30.ide.usages.RemoteUsagesWindowTopComponent")
11.69 -@ActionReference(path = "Menu/Window" /*, position = 333 */)
11.70 -@TopComponent.OpenActionRegistration(displayName = "#CTL_RemoteUsagesWindowAction",
11.71 -preferredID = "RemoteUsagesWindowTopComponent")
11.72 -public final class RemoteUsagesWindowTopComponent extends TopComponent implements ExplorerManager.Provider {
11.73 -
11.74 - public RemoteUsagesWindowTopComponent() {
11.75 - initComponents();
11.76 - setName(NbBundle.getMessage(RemoteUsagesWindowTopComponent.class, "CTL_RemoteUsagesWindowTopComponent"));
11.77 - setToolTipText(NbBundle.getMessage(RemoteUsagesWindowTopComponent.class, "HINT_RemoteUsagesWindowTopComponent"));
11.78 -
11.79 - BeanTreeView btv = new BeanTreeView();
11.80 -
11.81 - add(btv, BorderLayout.CENTER);
11.82 -
11.83 - btv.setRootVisible(false);
11.84 - }
11.85 -
11.86 - /** This method is called from within the constructor to
11.87 - * initialize the form.
11.88 - * WARNING: Do NOT modify this code. The content of this method is
11.89 - * always regenerated by the Form Editor.
11.90 - */
11.91 - // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
11.92 - private void initComponents() {
11.93 -
11.94 - setLayout(new java.awt.BorderLayout());
11.95 - }// </editor-fold>//GEN-END:initComponents
11.96 -
11.97 - // Variables declaration - do not modify//GEN-BEGIN:variables
11.98 - // End of variables declaration//GEN-END:variables
11.99 - @Override
11.100 - public void componentOpened() {
11.101 - // TODO add custom code on component opening
11.102 - }
11.103 -
11.104 - @Override
11.105 - public void componentClosed() {
11.106 - // TODO add custom code on component closing
11.107 - }
11.108 -
11.109 - void writeProperties(java.util.Properties p) {
11.110 - // better to version settings since initial version as advocated at
11.111 - // http://wiki.apidesign.org/wiki/PropertyFiles
11.112 - p.setProperty("version", "1.0");
11.113 - // TODO store your settings
11.114 - }
11.115 -
11.116 - void readProperties(java.util.Properties p) {
11.117 - String version = p.getProperty("version");
11.118 - // TODO read your settings according to their version
11.119 - }
11.120 -
11.121 - @Override
11.122 - public int getPersistenceType() {
11.123 - return PERSISTENCE_NEVER;
11.124 - }
11.125 -
11.126 - private final ExplorerManager manager = new ExplorerManager();
11.127 -
11.128 - @Override
11.129 - public ExplorerManager getExplorerManager() {
11.130 - return manager;
11.131 - }
11.132 -
11.133 - @Override
11.134 - public void open() {
11.135 - Mode outputMode = WindowManager.getDefault().findMode("output");
11.136 -
11.137 - if (outputMode != null)
11.138 - outputMode.dockInto(this);
11.139 - super.open();
11.140 - requestActive();
11.141 - requestFocusInWindow(false);
11.142 - }
11.143 -
11.144 - public static void openFor(Node n) {
11.145 - RemoteUsagesWindowTopComponent c = new RemoteUsagesWindowTopComponent();
11.146 -
11.147 - c.manager.setRootContext(n);
11.148 - c.open();
11.149 - }
11.150 -}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteWhereUsedQuery.java Wed Aug 15 14:33:00 2012 +0200
12.3 @@ -0,0 +1,238 @@
12.4 +/*
12.5 + * To change this template, choose Tools | Templates
12.6 + * and open the template in the editor.
12.7 + */
12.8 +package org.netbeans.modules.jackpot30.ide.usages;
12.9 +
12.10 +import java.util.ArrayList;
12.11 +import java.util.Collections;
12.12 +import java.util.EnumSet;
12.13 +import java.util.Iterator;
12.14 +import java.util.List;
12.15 +import java.util.Set;
12.16 +import java.util.concurrent.atomic.AtomicBoolean;
12.17 +import javax.swing.Icon;
12.18 +import org.netbeans.api.fileinfo.NonRecursiveFolder;
12.19 +import org.netbeans.api.java.source.ElementHandle;
12.20 +import org.netbeans.api.java.source.TreePathHandle;
12.21 +import org.netbeans.modules.jackpot30.ide.usages.RemoteUsages.SearchOptions;
12.22 +import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
12.23 +import org.netbeans.modules.refactoring.api.AbstractRefactoring;
12.24 +import org.netbeans.modules.refactoring.api.Problem;
12.25 +import org.netbeans.modules.refactoring.api.RefactoringElement;
12.26 +import org.netbeans.modules.refactoring.api.Scope;
12.27 +import org.netbeans.modules.refactoring.api.ScopeDescription;
12.28 +import org.netbeans.modules.refactoring.api.ScopeProvider;
12.29 +import org.netbeans.modules.refactoring.api.WhereUsedQuery;
12.30 +import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
12.31 +import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
12.32 +import org.netbeans.modules.refactoring.spi.RefactoringPluginFactory;
12.33 +import org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImplementation;
12.34 +import org.netbeans.modules.refactoring.spi.ui.ExpandableTreeElement;
12.35 +import org.netbeans.modules.refactoring.spi.ui.TreeElement;
12.36 +import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory;
12.37 +import org.netbeans.modules.refactoring.spi.ui.TreeElementFactoryImplementation;
12.38 +import org.openide.filesystems.FileObject;
12.39 +import org.openide.text.PositionBounds;
12.40 +import org.openide.util.Lookup;
12.41 +import org.openide.util.lookup.Lookups;
12.42 +import org.openide.util.lookup.ServiceProvider;
12.43 +
12.44 +/**
12.45 + *
12.46 + * @author lahvac
12.47 + */
12.48 +public class RemoteWhereUsedQuery implements RefactoringPlugin {
12.49 +
12.50 + private final WhereUsedQuery what;
12.51 +
12.52 + public RemoteWhereUsedQuery(WhereUsedQuery what) {
12.53 + this.what = what;
12.54 + }
12.55 +
12.56 + @Override
12.57 + public Problem preCheck() {
12.58 + return null;
12.59 + }
12.60 +
12.61 + @Override
12.62 + public Problem checkParameters() {
12.63 + return null;
12.64 + }
12.65 +
12.66 + @Override
12.67 + public Problem fastCheckParameters() {
12.68 + return null;
12.69 + }
12.70 +
12.71 + @Override
12.72 + public void cancelRequest() { }
12.73 +
12.74 + @Override
12.75 + public Problem prepare(RefactoringElementsBag refactoringElements) {
12.76 + if (what.getContext().lookup(Scope.class) != REMOTE_SCOPE) return null;
12.77 +
12.78 + TreePathHandle handle = what.getRefactoringSource().lookup(TreePathHandle.class);
12.79 + ElementHandle<?> toSearch = handle.getElementHandle();
12.80 + Set<SearchOptions> searchOptions = EnumSet.noneOf(SearchOptions.class);
12.81 +
12.82 + for (FileObject found : RemoteUsages.findUsages(toSearch, searchOptions, /*XXX*/new AtomicBoolean())) {
12.83 + Impl i = new Impl(found, toSearch, searchOptions);
12.84 +
12.85 + refactoringElements.add(what, i);
12.86 + }
12.87 +
12.88 + return null;
12.89 + }
12.90 +
12.91 + private static final class Impl extends SimpleRefactoringElementImplementation {
12.92 +
12.93 + private final FileObject file;
12.94 + private final ElementHandle<?> eh;
12.95 + private final Set<SearchOptions> searchOptions;
12.96 +
12.97 + public Impl(FileObject file, ElementHandle<?> eh, Set<SearchOptions> searchOptions) {
12.98 + this.file = file;
12.99 + this.eh = eh;
12.100 + this.searchOptions = searchOptions;
12.101 + }
12.102 +
12.103 + @Override
12.104 + public String getText() {
12.105 + return file.getNameExt(); //XXX
12.106 + }
12.107 +
12.108 + @Override
12.109 + public String getDisplayText() {
12.110 + return getText();
12.111 + }
12.112 +
12.113 + @Override
12.114 + public void performChange() {
12.115 + throw new UnsupportedOperationException("Nothing to perform.");
12.116 + }
12.117 +
12.118 + @Override
12.119 + public Lookup getLookup() {
12.120 + return Lookups.singleton(this);
12.121 + }
12.122 +
12.123 + @Override
12.124 + public FileObject getParentFile() {
12.125 + return file.getParent();
12.126 + }
12.127 +
12.128 + @Override
12.129 + public PositionBounds getPosition() {
12.130 + return null;
12.131 + }
12.132 +
12.133 + }
12.134 +
12.135 + @ServiceProvider(service=RefactoringPluginFactory.class)
12.136 + public static final class FactoryImpl implements RefactoringPluginFactory {
12.137 +
12.138 + @Override
12.139 + public RefactoringPlugin createInstance(AbstractRefactoring refactoring) {
12.140 + if (refactoring instanceof WhereUsedQuery) {
12.141 + return new RemoteWhereUsedQuery((WhereUsedQuery) refactoring);
12.142 + }
12.143 +
12.144 + return null;
12.145 + }
12.146 +
12.147 + }
12.148 +
12.149 + @ServiceProvider(service=TreeElementFactoryImplementation.class, position=1)
12.150 + public static final class TreeFactoryImpl implements TreeElementFactoryImplementation {
12.151 +
12.152 + @Override
12.153 + public TreeElement getTreeElement(Object o) {
12.154 + if (o instanceof RefactoringElement) {
12.155 + Impl i = ((RefactoringElement) o).getLookup().lookup(Impl.class);
12.156 +
12.157 + if (i != null) {
12.158 + TreeElement fileElement = TreeElementFactory.getTreeElement(i.file);
12.159 +
12.160 + assert fileElement != null;
12.161 +
12.162 + return new TreeElementImpl(i, fileElement);
12.163 + }
12.164 + }
12.165 + return null;
12.166 + }
12.167 +
12.168 + @Override
12.169 + public void cleanUp() {
12.170 +
12.171 + }
12.172 +
12.173 + }
12.174 +
12.175 + private static final class TreeElementImpl implements ExpandableTreeElement {
12.176 +
12.177 + private final Impl impl;
12.178 + private final TreeElement delegateTo;
12.179 +
12.180 + public TreeElementImpl(Impl impl, TreeElement delegateTo) {
12.181 + this.impl = impl;
12.182 + this.delegateTo = delegateTo;
12.183 + }
12.184 +
12.185 + @Override
12.186 + public TreeElement getParent(boolean isLogical) {
12.187 + return delegateTo.getParent(isLogical);
12.188 + }
12.189 +
12.190 + @Override
12.191 + public Icon getIcon() {
12.192 + return delegateTo.getIcon();
12.193 + }
12.194 +
12.195 + @Override
12.196 + public String getText(boolean isLogical) {
12.197 + return delegateTo.getText(isLogical);
12.198 + }
12.199 +
12.200 + @Override
12.201 + public Object getUserObject() {
12.202 + return delegateTo.getUserObject();
12.203 + }
12.204 +
12.205 + @Override
12.206 + public Iterator<TreeElement> iterator() {
12.207 + final List<TreeElement> result = new ArrayList<TreeElement>();
12.208 +
12.209 + RemoteUsages.computeOccurrences(impl.file, impl.eh, impl.searchOptions, this, result);
12.210 +
12.211 + return result.iterator();
12.212 + }
12.213 +
12.214 + @Override
12.215 + public int estimateSubNodesCount() {
12.216 + return 1;
12.217 + }
12.218 + }
12.219 +
12.220 + private static final Scope REMOTE_SCOPE = Scope.create(Collections.<FileObject>emptyList(), Collections.<NonRecursiveFolder>emptyList(), Collections.<FileObject>emptyList());
12.221 + private static final ScopeDescription REMOTE_SCOPE_DESCRIPTION = new ScopeDescription("remote-scope", "Remote Scope", null, "A") {
12.222 + @Override public Scope getScope() {
12.223 + return REMOTE_SCOPE;
12.224 + }
12.225 + };
12.226 +
12.227 + @ServiceProvider(service=ScopeProvider.class)
12.228 + public static final class ScopeProviderImpl implements ScopeProvider {
12.229 +
12.230 + @Override
12.231 + public Iterable<ScopeDescription> scopesFor(Lookup source) {
12.232 + if (RemoteIndex.loadIndices().iterator().hasNext()) {
12.233 + return Collections.singletonList(REMOTE_SCOPE_DESCRIPTION);
12.234 + } else {
12.235 + return Collections.emptyList();
12.236 + }
12.237 + }
12.238 +
12.239 + }
12.240 +
12.241 +}
13.1 --- a/remoting/ide/usages/test/unit/src/org/netbeans/modules/jackpot30/ide/usages/NodesTest.java Fri Aug 10 22:46:58 2012 +0200
13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
13.3 @@ -1,158 +0,0 @@
13.4 -/*
13.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
13.6 - *
13.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
13.8 - *
13.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
13.10 - * Other names may be trademarks of their respective owners.
13.11 - *
13.12 - * The contents of this file are subject to the terms of either the GNU
13.13 - * General Public License Version 2 only ("GPL") or the Common
13.14 - * Development and Distribution License("CDDL") (collectively, the
13.15 - * "License"). You may not use this file except in compliance with the
13.16 - * License. You can obtain a copy of the License at
13.17 - * http://www.netbeans.org/cddl-gplv2.html
13.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13.19 - * specific language governing permissions and limitations under the
13.20 - * License. When distributing the software, include this License Header
13.21 - * Notice in each file and include the License file at
13.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
13.23 - * particular file as subject to the "Classpath" exception as provided
13.24 - * by Oracle in the GPL Version 2 section of the License file that
13.25 - * accompanied this code. If applicable, add the following below the
13.26 - * License Header, with the fields enclosed by brackets [] replaced by
13.27 - * your own identifying information:
13.28 - * "Portions Copyrighted [year] [name of copyright owner]"
13.29 - *
13.30 - * If you wish your version of this file to be governed by only the CDDL
13.31 - * or only the GPL Version 2, indicate your decision by adding
13.32 - * "[Contributor] elects to include this software in this distribution
13.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
13.34 - * single choice of license, a recipient has the option to distribute
13.35 - * your version of this file under either the CDDL, the GPL Version 2 or
13.36 - * to extend the choice of license to its licensees as provided above.
13.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
13.38 - * Version 2 license, then the option applies only if the new code is
13.39 - * made subject to such option by the copyright holder.
13.40 - *
13.41 - * Contributor(s):
13.42 - *
13.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
13.44 - */
13.45 -package org.netbeans.modules.jackpot30.ide.usages;
13.46 -
13.47 -import java.util.ArrayList;
13.48 -import java.util.EnumSet;
13.49 -import java.util.List;
13.50 -import javax.lang.model.element.TypeElement;
13.51 -import org.netbeans.api.java.source.CompilationInfo;
13.52 -import org.netbeans.api.java.source.ElementHandle;
13.53 -import org.netbeans.api.java.source.JavaSource;
13.54 -import org.netbeans.api.java.source.JavaSource.Phase;
13.55 -import org.netbeans.api.java.source.SourceUtilsTestUtil;
13.56 -import org.netbeans.api.java.source.TestUtilities;
13.57 -import org.netbeans.junit.NbTestCase;
13.58 -import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
13.59 -import org.openide.filesystems.FileObject;
13.60 -import org.openide.filesystems.FileUtil;
13.61 -import org.openide.nodes.Node;
13.62 -
13.63 -/**
13.64 - *
13.65 - * @author lahvac
13.66 - */
13.67 -public class NodesTest extends NbTestCase {
13.68 -
13.69 - public NodesTest(String testName) {
13.70 - super(testName);
13.71 - }
13.72 -
13.73 - public void testA() throws Exception {
13.74 - FileObject data = FileUtil.createData(src, "test/Test.java");
13.75 - TestUtilities.copyStringToFile(data, "package test;\n" +
13.76 - "public class Test {\n" +
13.77 - " public Test () {}\n" +
13.78 - " private void test() { new Test(); }\n" +
13.79 - "}\n");
13.80 - CompilationInfo info = SourceUtilsTestUtil.getCompilationInfo(JavaSource.forFileObject(data), Phase.RESOLVED);
13.81 - ElementHandle<?> eh = ElementHandle.create(info.getTopLevelElements().get(0).getEnclosedElements().get(0));
13.82 - List<Node> constructed = new ArrayList<Node>();
13.83 -
13.84 - Nodes.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.USAGES), constructed);
13.85 -
13.86 - Node n = constructed.get(0);
13.87 -
13.88 - assertEquals(" private void test() { new <b>Test</b>(); }<br>", n.getHtmlDisplayName());
13.89 - }
13.90 -
13.91 - public void testMethodImplementations() throws Exception {
13.92 - FileObject data = FileUtil.createData(src, "test/Test.java");
13.93 - TestUtilities.copyStringToFile(data, "package test;\n" +
13.94 - "public class Test implements Runnable {\n" +
13.95 - " public void run() {\n" +
13.96 - " Runnable r = null;\n" +
13.97 - " r.run();\n" +
13.98 - " }\n" +
13.99 - "}\n");
13.100 - CompilationInfo info = SourceUtilsTestUtil.getCompilationInfo(JavaSource.forFileObject(data), Phase.RESOLVED);
13.101 - TypeElement runnable = info.getElements().getTypeElement("java.lang.Runnable");
13.102 -
13.103 - assertNotNull(runnable);
13.104 -
13.105 - ElementHandle<?> eh = ElementHandle.create(runnable.getEnclosedElements().get(0));
13.106 - List<Node> constructed = new ArrayList<Node>();
13.107 -
13.108 - Nodes.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), constructed);
13.109 -
13.110 - assertEquals(1, constructed.size());
13.111 -
13.112 - Node n = constructed.get(0);
13.113 -
13.114 - assertEquals(" public void <b>run</b>() {<br>", n.getHtmlDisplayName());
13.115 - }
13.116 -
13.117 - public void testSubtypes() throws Exception {
13.118 - FileObject data = FileUtil.createData(src, "test/Test.java");
13.119 - TestUtilities.copyStringToFile(data, "package test;\n" +
13.120 - "public class Test implements Runnable {\n" +
13.121 - " public void run() {\n" +
13.122 - " Runnable r = null;\n" +
13.123 - " r.run();\n" +
13.124 - " }\n" +
13.125 - "}\n");
13.126 - CompilationInfo info = SourceUtilsTestUtil.getCompilationInfo(JavaSource.forFileObject(data), Phase.RESOLVED);
13.127 - TypeElement runnable = info.getElements().getTypeElement("java.lang.Runnable");
13.128 -
13.129 - assertNotNull(runnable);
13.130 -
13.131 - ElementHandle<?> eh = ElementHandle.create(runnable);
13.132 - List<Node> constructed = new ArrayList<Node>();
13.133 -
13.134 - Nodes.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), constructed);
13.135 -
13.136 - assertEquals(1, constructed.size());
13.137 -
13.138 - Node n = constructed.get(0);
13.139 -
13.140 - assertEquals("public class <b>Test</b> implements Runnable {<br>", n.getHtmlDisplayName());
13.141 - }
13.142 -
13.143 - @Override
13.144 - protected void setUp() throws Exception {
13.145 - SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
13.146 - prepareTest();
13.147 - super.setUp();
13.148 - }
13.149 -
13.150 - private FileObject src;
13.151 -
13.152 - private void prepareTest() throws Exception {
13.153 - FileObject workdir = SourceUtilsTestUtil.makeScratchDir(this);
13.154 -
13.155 - src = FileUtil.createFolder(workdir, "src");
13.156 -
13.157 - FileObject cache = FileUtil.createFolder(workdir, "cache");
13.158 -
13.159 - CacheFolder.setCacheFolder(cache);
13.160 - }
13.161 -}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/remoting/ide/usages/test/unit/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsagesTest.java Wed Aug 15 14:33:00 2012 +0200
14.3 @@ -0,0 +1,159 @@
14.4 +/*
14.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
14.6 + *
14.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
14.8 + *
14.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
14.10 + * Other names may be trademarks of their respective owners.
14.11 + *
14.12 + * The contents of this file are subject to the terms of either the GNU
14.13 + * General Public License Version 2 only ("GPL") or the Common
14.14 + * Development and Distribution License("CDDL") (collectively, the
14.15 + * "License"). You may not use this file except in compliance with the
14.16 + * License. You can obtain a copy of the License at
14.17 + * http://www.netbeans.org/cddl-gplv2.html
14.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
14.19 + * specific language governing permissions and limitations under the
14.20 + * License. When distributing the software, include this License Header
14.21 + * Notice in each file and include the License file at
14.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
14.23 + * particular file as subject to the "Classpath" exception as provided
14.24 + * by Oracle in the GPL Version 2 section of the License file that
14.25 + * accompanied this code. If applicable, add the following below the
14.26 + * License Header, with the fields enclosed by brackets [] replaced by
14.27 + * your own identifying information:
14.28 + * "Portions Copyrighted [year] [name of copyright owner]"
14.29 + *
14.30 + * If you wish your version of this file to be governed by only the CDDL
14.31 + * or only the GPL Version 2, indicate your decision by adding
14.32 + * "[Contributor] elects to include this software in this distribution
14.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
14.34 + * single choice of license, a recipient has the option to distribute
14.35 + * your version of this file under either the CDDL, the GPL Version 2 or
14.36 + * to extend the choice of license to its licensees as provided above.
14.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
14.38 + * Version 2 license, then the option applies only if the new code is
14.39 + * made subject to such option by the copyright holder.
14.40 + *
14.41 + * Contributor(s):
14.42 + *
14.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
14.44 + */
14.45 +package org.netbeans.modules.jackpot30.ide.usages;
14.46 +
14.47 +import java.util.ArrayList;
14.48 +import java.util.EnumSet;
14.49 +import java.util.List;
14.50 +import javax.lang.model.element.TypeElement;
14.51 +import org.netbeans.api.java.source.CompilationInfo;
14.52 +import org.netbeans.api.java.source.ElementHandle;
14.53 +import org.netbeans.api.java.source.JavaSource;
14.54 +import org.netbeans.api.java.source.JavaSource.Phase;
14.55 +import org.netbeans.api.java.source.SourceUtilsTestUtil;
14.56 +import org.netbeans.api.java.source.TestUtilities;
14.57 +import org.netbeans.junit.NbTestCase;
14.58 +import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
14.59 +import org.netbeans.modules.refactoring.spi.ui.TreeElement;
14.60 +import org.openide.filesystems.FileObject;
14.61 +import org.openide.filesystems.FileUtil;
14.62 +import org.openide.nodes.Node;
14.63 +
14.64 +/**
14.65 + *
14.66 + * @author lahvac
14.67 + */
14.68 +public class RemoteUsagesTest extends NbTestCase {
14.69 +
14.70 + public RemoteUsagesTest(String testName) {
14.71 + super(testName);
14.72 + }
14.73 +
14.74 + public void testA() throws Exception {
14.75 + FileObject data = FileUtil.createData(src, "test/Test.java");
14.76 + TestUtilities.copyStringToFile(data, "package test;\n" +
14.77 + "public class Test {\n" +
14.78 + " public Test () {}\n" +
14.79 + " private void test() { new Test(); }\n" +
14.80 + "}\n");
14.81 + CompilationInfo info = SourceUtilsTestUtil.getCompilationInfo(JavaSource.forFileObject(data), Phase.RESOLVED);
14.82 + ElementHandle<?> eh = ElementHandle.create(info.getTopLevelElements().get(0).getEnclosedElements().get(0));
14.83 + List<TreeElement> constructed = new ArrayList<TreeElement>();
14.84 +
14.85 + RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.USAGES), null, constructed);
14.86 +
14.87 + TreeElement n = constructed.get(0);
14.88 +
14.89 + assertEquals("private void test() { new <b>Test</b>(); }", n.getText(true));
14.90 + }
14.91 +
14.92 + public void testMethodImplementations() throws Exception {
14.93 + FileObject data = FileUtil.createData(src, "test/Test.java");
14.94 + TestUtilities.copyStringToFile(data, "package test;\n" +
14.95 + "public class Test implements Runnable {\n" +
14.96 + " public void run() {\n" +
14.97 + " Runnable r = null;\n" +
14.98 + " r.run();\n" +
14.99 + " }\n" +
14.100 + "}\n");
14.101 + CompilationInfo info = SourceUtilsTestUtil.getCompilationInfo(JavaSource.forFileObject(data), Phase.RESOLVED);
14.102 + TypeElement runnable = info.getElements().getTypeElement("java.lang.Runnable");
14.103 +
14.104 + assertNotNull(runnable);
14.105 +
14.106 + ElementHandle<?> eh = ElementHandle.create(runnable.getEnclosedElements().get(0));
14.107 + List<TreeElement> constructed = new ArrayList<TreeElement>();
14.108 +
14.109 + RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), null, constructed);
14.110 +
14.111 + assertEquals(1, constructed.size());
14.112 +
14.113 + TreeElement n = constructed.get(0);
14.114 +
14.115 + assertEquals("public void <b>run</b>() {", n.getText(true));
14.116 + }
14.117 +
14.118 + public void testSubtypes() throws Exception {
14.119 + FileObject data = FileUtil.createData(src, "test/Test.java");
14.120 + TestUtilities.copyStringToFile(data, "package test;\n" +
14.121 + "public class Test implements Runnable {\n" +
14.122 + " public void run() {\n" +
14.123 + " Runnable r = null;\n" +
14.124 + " r.run();\n" +
14.125 + " }\n" +
14.126 + "}\n");
14.127 + CompilationInfo info = SourceUtilsTestUtil.getCompilationInfo(JavaSource.forFileObject(data), Phase.RESOLVED);
14.128 + TypeElement runnable = info.getElements().getTypeElement("java.lang.Runnable");
14.129 +
14.130 + assertNotNull(runnable);
14.131 +
14.132 + ElementHandle<?> eh = ElementHandle.create(runnable);
14.133 + List<TreeElement> constructed = new ArrayList<TreeElement>();
14.134 +
14.135 + RemoteUsages.computeOccurrences(data, eh, EnumSet.of(RemoteUsages.SearchOptions.SUB), null, constructed);
14.136 +
14.137 + assertEquals(1, constructed.size());
14.138 +
14.139 + TreeElement n = constructed.get(0);
14.140 +
14.141 + assertEquals("public class <b>Test</b> implements Runnable {", n.getText(true));
14.142 + }
14.143 +
14.144 + @Override
14.145 + protected void setUp() throws Exception {
14.146 + SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
14.147 + prepareTest();
14.148 + super.setUp();
14.149 + }
14.150 +
14.151 + private FileObject src;
14.152 +
14.153 + private void prepareTest() throws Exception {
14.154 + FileObject workdir = SourceUtilsTestUtil.makeScratchDir(this);
14.155 +
14.156 + src = FileUtil.createFolder(workdir, "src");
14.157 +
14.158 + FileObject cache = FileUtil.createFolder(workdir, "cache");
14.159 +
14.160 + CacheFolder.setCacheFolder(cache);
14.161 + }
14.162 +}