This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 248941
Collapse All | Expand All

(-)a/java.sourceui/src/org/netbeans/modules/java/source/ui/JavaSymbolDescriptor.java (-138 / +136 lines)
Lines 42-241 Link Here
42
42
43
package org.netbeans.modules.java.source.ui;
43
package org.netbeans.modules.java.source.ui;
44
44
45
import java.io.File;
46
import java.io.IOException;
45
import java.io.IOException;
47
import java.net.URL;
46
import java.util.ArrayList;
47
import java.util.Collection;
48
import java.util.Collections;
49
import java.util.List;
48
import java.util.Set;
50
import java.util.Set;
51
import java.util.concurrent.CopyOnWriteArrayList;
52
import java.util.concurrent.atomic.AtomicBoolean;
53
import javax.lang.model.element.Element;
49
import javax.lang.model.element.ElementKind;
54
import javax.lang.model.element.ElementKind;
50
import javax.lang.model.element.Modifier;
55
import javax.lang.model.element.Modifier;
51
import javax.lang.model.element.TypeElement;
56
import javax.lang.model.element.TypeElement;
52
import javax.swing.Icon;
57
import javax.swing.Icon;
53
import org.netbeans.api.annotations.common.CheckForNull;
54
import org.netbeans.api.annotations.common.NonNull;
58
import org.netbeans.api.annotations.common.NonNull;
55
import org.netbeans.api.annotations.common.NullAllowed;
59
import org.netbeans.api.annotations.common.NullAllowed;
56
import org.netbeans.api.java.classpath.ClassPath;
57
import org.netbeans.api.java.source.ClasspathInfo;
60
import org.netbeans.api.java.source.ClasspathInfo;
61
import org.netbeans.api.java.source.CompilationController;
58
import org.netbeans.api.java.source.ElementHandle;
62
import org.netbeans.api.java.source.ElementHandle;
59
import org.netbeans.api.java.source.SourceUtils;
63
import org.netbeans.api.java.source.JavaSource;
60
import org.netbeans.api.java.source.ui.ElementOpen;
64
import org.netbeans.api.java.source.Task;
61
import org.netbeans.api.project.Project;
65
import org.netbeans.api.project.Project;
62
import org.netbeans.api.project.ProjectInformation;
66
import org.netbeans.modules.java.source.indexing.TransactionContext;
63
import org.netbeans.api.project.ProjectUtils;
67
import org.netbeans.modules.java.source.parsing.FileManagerTransaction;
64
import org.netbeans.modules.java.source.parsing.FileObjects;
68
import org.netbeans.modules.java.source.parsing.ProcessorGenerated;
65
import org.netbeans.modules.java.source.usages.ClassIndexImpl;
69
import org.netbeans.modules.java.source.usages.ClassIndexImpl;
66
import org.netbeans.modules.java.ui.Icons;
70
import org.netbeans.modules.java.source.usages.ClasspathInfoAccessor;
67
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
71
import org.netbeans.spi.jumpto.support.AsyncDescriptor;
72
import org.netbeans.spi.jumpto.support.DescriptorChangeEvent;
73
import org.netbeans.spi.jumpto.support.DescriptorChangeListener;
68
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
74
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
69
import org.openide.filesystems.FileObject;
75
import org.openide.filesystems.FileObject;
70
import org.openide.filesystems.FileUtil;
71
import org.openide.util.Exceptions;
76
import org.openide.util.Exceptions;
77
import org.openide.util.Pair;
78
import org.openide.util.Parameters;
79
import org.openide.util.RequestProcessor;
72
80
73
/**
81
/**
74
 *
82
 *
75
 * @author Tomas Zezula
83
 * @author Tomas Zezula
76
 */
84
 */
77
public class JavaSymbolDescriptor extends SymbolDescriptor {
85
final class AsyncJavaSymbolDescriptor extends JavaSymbolDescriptorBase implements AsyncDescriptor<SymbolDescriptor> {
78
86
79
    private final String simpleName;
87
    private static final RequestProcessor WORKER = new RequestProcessor(AsyncJavaSymbolDescriptor.class);
80
    private final String simpleNameSuffix;
88
    private static final String INIT = "<init>"; //NOI18N
81
    private final ElementHandle<TypeElement> owner;
82
    private final ElementHandle<?> me;
83
    private final ElementKind kind;
84
    private final Set<Modifier> modifiers;
85
    private final FileObject root;
86
    private final Project project;
87
    private final ClassIndexImpl ci;
88
    private FileObject cachedFo;
89
    private volatile String cachedPath;
90
89
91
    public JavaSymbolDescriptor (
90
    private final String ident;
92
            @NonNull final String simpleName,
91
    private final List<DescriptorChangeListener<SymbolDescriptor>> listeners;
93
            @NullAllowed final String simpleNameSuffix,
92
    private final AtomicBoolean initialized;
94
            @NonNull final ElementKind kind,
93
95
            @NonNull final Set<Modifier> modifiers,
94
    AsyncJavaSymbolDescriptor (
96
            @NonNull final ElementHandle<TypeElement> owner,
97
            @NonNull final ElementHandle<?> me,
98
            @NullAllowed final Project project,
95
            @NullAllowed final Project project,
99
            @NonNull final FileObject root,
96
            @NonNull final FileObject root,
100
            @NonNull final ClassIndexImpl ci) {
97
            @NonNull final ClassIndexImpl ci,
101
        assert simpleName != null;
98
            @NonNull final ElementHandle<TypeElement> owner,
102
        assert kind != null;
99
            @NonNull final String ident) {
103
        assert modifiers != null;
100
        super(owner, project, root, ci);
104
        assert owner != null;
101
        assert ident != null;
105
        assert me != null;
102
        this.ident = ident;
106
        assert root != null;
103
        this.listeners = new CopyOnWriteArrayList<>();
107
        assert ci != null;
104
        this.initialized = new AtomicBoolean();
108
        this.simpleName = simpleName;
109
        this.simpleNameSuffix = simpleNameSuffix;
110
        this.kind = kind;
111
        this.modifiers = modifiers;
112
        this.owner = owner;
113
        this.me = me;
114
        this.root = root;
115
        this.project = project;
116
        this.ci = ci;
117
    }
105
    }
118
106
119
    @Override
107
    @Override
120
    public Icon getIcon() {
108
    public Icon getIcon() {
121
        return Icons.getElementIcon(kind, modifiers);
109
        initialize();
110
        return null;
122
    }
111
    }
123
112
124
    @Override
113
    @Override
125
    public String getSymbolName() {
114
    public String getSymbolName() {
126
        return simpleNameSuffix == null ?
115
        initialize();
127
                simpleName :
116
        return ident;
128
                simpleName + simpleNameSuffix;
129
    }
117
    }
130
118
131
    @Override
119
    @Override
132
    public String getSimpleName() {
120
    public String getSimpleName() {
133
        return simpleName;
121
        return ident;
134
    }
122
    }
135
123
136
    @Override
124
    @Override
137
    public String getOwnerName() {
125
    public void open() {
138
        return owner.getQualifiedName();
126
        final Collection<? extends SymbolDescriptor> symbols = resolve();
127
        if (!symbols.isEmpty()) {
128
            symbols.iterator().next().open();
129
        }
139
    }
130
    }
140
131
141
132
    private void initialize() {
142
    @Override
133
        if (initialized.compareAndSet(false, true)) {
143
    public FileObject getFileObject() {
134
            final Runnable action = new Runnable() {
144
        if (cachedFo == null) {
135
                @Override
145
            final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPath.EMPTY,
136
                public void run() {
146
                    ClassPath.EMPTY, ClassPathSupport.createClassPath(root));
137
                    final Collection<? extends SymbolDescriptor> symbols = resolve();
147
            cachedFo = SourceUtils.getFile(owner, cpInfo);
138
                    fireDescriptorChange(symbols);
148
        }
149
        return cachedFo;
150
    }
151
152
    @Override
153
    @NonNull
154
    public String getFileDisplayPath() {
155
        String res = cachedPath;
156
        if (res == null) {
157
            final File rootFile = FileUtil.toFile(root);
158
            if (rootFile != null) {
159
                try {
160
                    final String binaryName = owner.getBinaryName();
161
                    String relativePath = ci.getSourceName(binaryName);
162
                    if (relativePath == null) {
163
                        relativePath = binaryName;
164
                        int lastDot = relativePath.lastIndexOf('.');    //NOI18N
165
                        int csIndex = relativePath.indexOf('$', lastDot);     //NOI18N
166
                        if (csIndex > 0 && csIndex < relativePath.length()-1) {
167
                            relativePath = binaryName.substring(0, csIndex);
168
                        }
169
                        relativePath = String.format(
170
                            "%s.%s",    //NOI18N
171
                            FileObjects.convertPackage2Folder(relativePath, File.separatorChar),
172
                            FileObjects.JAVA);
173
                    }
174
                    res = new File (rootFile, relativePath).getAbsolutePath();
175
                } catch (IOException | InterruptedException e) {
176
                    Exceptions.printStackTrace(e);
177
                }
139
                }
178
            }
140
            };
179
            if (res == null) {
141
            WORKER.execute(action);
180
                final FileObject fo = getFileObject();
181
                res = fo == null ?
182
                    "" :    //NOI18N
183
                    FileUtil.getFileDisplayName(fo);
184
            }
185
            cachedPath = res;
186
        }
187
        return res;
188
    }
189
190
191
192
    @Override
193
    public void open() {
194
        FileObject file = getFileObject();
195
        if (file != null) {
196
	    ClasspathInfo cpInfo = ClasspathInfo.create(file);
197
198
	    ElementOpen.open(cpInfo, me);
199
        }
142
        }
200
    }
143
    }
201
144
202
    @Override
145
    @Override
203
    public String getProjectName() {
146
    public void addDescriptorChangeListener(@NonNull final DescriptorChangeListener<SymbolDescriptor> listener) {
204
        final ProjectInformation info = getProjectInfo();
147
        Parameters.notNull("listener", listener);
205
        return info == null ?
148
        listeners.add(listener);
206
            "" :    //NOI18N
207
            info.getDisplayName();
208
    }
149
    }
209
150
210
    @Override
151
    @Override
211
    public Icon getProjectIcon() {
152
    public void removeDescriptorChangeListener(@NonNull final DescriptorChangeListener<SymbolDescriptor> listener) {
212
        final ProjectInformation info = getProjectInfo();
153
        Parameters.notNull("listener", listener);
213
        return info == null ?
154
        listeners.remove(listener);
214
            null :
215
            info.getIcon();
216
    }
155
    }
217
156
218
    @Override
157
    private void fireDescriptorChange(Collection<? extends SymbolDescriptor> replacement) {
219
    public int getOffset() {
158
        final DescriptorChangeEvent<SymbolDescriptor> event = new DescriptorChangeEvent<>(
220
        //todo: fixme
159
            this,
221
        return -1;
160
            replacement);
161
        for (DescriptorChangeListener<SymbolDescriptor> l : listeners) {
162
            l.descriptorChanged(event);
163
        }
222
    }
164
    }
223
165
224
    @NonNull
166
    @NonNull
225
    public ElementKind getElementKind() {
167
    private Collection<? extends SymbolDescriptor> resolve() {
226
        return kind;
168
        try {
169
            final List<SymbolDescriptor> symbols = new ArrayList<>();
170
            TransactionContext.
171
                beginTrans().
172
                register(FileManagerTransaction.class, FileManagerTransaction.read()).
173
                register(ProcessorGenerated.class, ProcessorGenerated.nullWrite());
174
            try {
175
                final ClasspathInfo cpInfo = ClasspathInfoAccessor.getINSTANCE().create(getRoot(),null,true,true,false,false);
176
                final JavaSource js = JavaSource.create(cpInfo);
177
                js.runUserActionTask(new Task<CompilationController>() {
178
                    @Override
179
                    public void run (final CompilationController controller) {
180
                        final TypeElement te = getOwner().resolve(controller);
181
                        if (te != null) {
182
                            if (ident.equals(getSimpleName(te, null)) /*TODO && matchesRestrictions(te, restriction)*/) {
183
                                final String simpleName = te.getSimpleName().toString();
184
                                final String simpleNameSuffix = null;
185
                                final ElementKind kind = te.getKind();
186
                                final Set<Modifier> modifiers = te.getModifiers();
187
                                final ElementHandle<?> me = ElementHandle.create(te);
188
                                symbols.add(new ResolvedJavaSymbolDescriptor(
189
                                        AsyncJavaSymbolDescriptor.this,
190
                                        simpleName,
191
                                        simpleNameSuffix,
192
                                        kind,
193
                                        modifiers,
194
                                        me));
195
                            }
196
                            for (Element ne : te.getEnclosedElements()) {
197
                                if (ident.equals(getSimpleName(ne, te)) /*TODO && matchesRestrictions(ne, restriction)*/) {
198
                                    final Pair<String,String> name = JavaSymbolProvider.getDisplayName(ne, te);
199
                                    final String simpleName = name.first();
200
                                    final String simpleNameSuffix = name.second();
201
                                    final ElementKind kind = ne.getKind();
202
                                    final Set<Modifier> modifiers = ne.getModifiers();
203
                                    final ElementHandle<?> me = ElementHandle.create(ne);
204
                                    symbols.add(new ResolvedJavaSymbolDescriptor(
205
                                            AsyncJavaSymbolDescriptor.this,
206
                                            simpleName,
207
                                            simpleNameSuffix,
208
                                            kind,
209
                                            modifiers,
210
                                            me));
211
                                }
212
                            }
213
                        }
214
                    }
215
                }, true);
216
            }finally {
217
                TransactionContext.get().commit();
218
            }
219
            return symbols;
220
        } catch (IOException e) {
221
            Exceptions.printStackTrace(e);
222
           return Collections.<SymbolDescriptor>emptyList();
223
        }
227
    }
224
    }
228
225
229
    @NonNull
226
    @NonNull
230
    public Set<? extends Modifier> getModifiers() {
227
    private static String getSimpleName (
231
        return modifiers;
228
            @NonNull final Element element,
229
            @NullAllowed final Element enclosingElement) {
230
        String result = element.getSimpleName().toString();
231
        if (enclosingElement != null && INIT.equals(result)) {
232
            result = enclosingElement.getSimpleName().toString();
233
        }
234
//TODO            if (!caseSensitive) {
235
        result = result.toLowerCase();
236
//            }
237
        return result;
232
    }
238
    }
233
234
    @CheckForNull
235
    private ProjectInformation getProjectInfo() {
236
        return project == null ?
237
            null :
238
            project.getLookup().lookup(ProjectInformation.class);   //Intentionally does not use ProjectUtils.getInformation() it does project icon annotation which is expensive
239
    }
240
241
}
239
}
(-)a/java.sourceui/src/org/netbeans/modules/java/source/ui/JavaSymbolDescriptorBase.java (+198 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.ui;
43
44
import java.io.File;
45
import java.io.IOException;
46
import javax.lang.model.element.TypeElement;
47
import javax.swing.Icon;
48
import org.netbeans.api.annotations.common.CheckForNull;
49
import org.netbeans.api.annotations.common.NonNull;
50
import org.netbeans.api.annotations.common.NullAllowed;
51
import org.netbeans.api.java.classpath.ClassPath;
52
import org.netbeans.api.java.source.ClasspathInfo;
53
import org.netbeans.api.java.source.ElementHandle;
54
import org.netbeans.api.java.source.SourceUtils;
55
import org.netbeans.api.project.Project;
56
import org.netbeans.api.project.ProjectInformation;
57
import org.netbeans.modules.java.source.parsing.FileObjects;
58
import org.netbeans.modules.java.source.usages.ClassIndexImpl;
59
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
60
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
61
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.FileUtil;
63
import org.openide.util.Exceptions;
64
65
/**
66
 *
67
 * @author Tomas Zezula
68
 */
69
abstract class JavaSymbolDescriptorBase extends SymbolDescriptor {
70
71
    private final ElementHandle<TypeElement> owner;
72
    private final Project project;
73
    private final FileObject root;
74
    private final ClassIndexImpl ci;
75
    private volatile FileObject cachedFo;
76
    private volatile String cachedPath;
77
78
    JavaSymbolDescriptorBase(
79
        @NonNull final ElementHandle<TypeElement> owner,
80
        @NullAllowed final Project project,
81
        @NonNull final FileObject root,
82
        @NonNull final ClassIndexImpl ci) {
83
        assert owner != null;
84
        assert root != null;
85
        assert ci != null;
86
        this.owner = owner;
87
        this.project = project;
88
        this.root = root;
89
        this.ci = ci;
90
    }
91
92
    JavaSymbolDescriptorBase(
93
        @NonNull final JavaSymbolDescriptorBase other) {
94
        this.owner = other.owner;
95
        this.project = other.project;
96
        this.root = other.root;
97
        this.ci = other.ci;
98
        this.cachedFo = other.cachedFo;
99
        this.cachedPath = other.cachedPath;
100
    }
101
102
    @Override
103
    @NonNull
104
    public final String getOwnerName() {
105
        return owner.getQualifiedName();
106
    }
107
108
    @Override
109
    @CheckForNull
110
    public final FileObject getFileObject() {
111
        FileObject res = cachedFo;
112
        if (res == null) {
113
            final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPath.EMPTY,
114
                    ClassPath.EMPTY, ClassPathSupport.createClassPath(root));
115
            res = cachedFo = SourceUtils.getFile(owner, cpInfo);
116
        }
117
        return res;
118
    }
119
120
    @Override
121
    @NonNull
122
    public final String getFileDisplayPath() {
123
        String res = cachedPath;
124
        if (res == null) {
125
            final File rootFile = FileUtil.toFile(root);
126
            if (rootFile != null) {
127
                try {
128
                    final String binaryName = owner.getBinaryName();
129
                    String relativePath = ci.getSourceName(binaryName);
130
                    if (relativePath == null) {
131
                        relativePath = binaryName;
132
                        int lastDot = relativePath.lastIndexOf('.');    //NOI18N
133
                        int csIndex = relativePath.indexOf('$', lastDot);     //NOI18N
134
                        if (csIndex > 0 && csIndex < relativePath.length()-1) {
135
                            relativePath = binaryName.substring(0, csIndex);
136
                        }
137
                        relativePath = String.format(
138
                            "%s.%s",    //NOI18N
139
                            FileObjects.convertPackage2Folder(relativePath, File.separatorChar),
140
                            FileObjects.JAVA);
141
                    }
142
                    res = new File (rootFile, relativePath).getAbsolutePath();
143
                } catch (IOException | InterruptedException e) {
144
                    Exceptions.printStackTrace(e);
145
                }
146
            }
147
            if (res == null) {
148
                final FileObject fo = getFileObject();
149
                res = fo == null ?
150
                    "" :    //NOI18N
151
                    FileUtil.getFileDisplayName(fo);
152
            }
153
            cachedPath = res;
154
        }
155
        return res;
156
    }
157
158
    @Override
159
    @NonNull
160
    public final String getProjectName() {
161
        final ProjectInformation info = getProjectInfo();
162
        return info == null ?
163
            "" :    //NOI18N
164
            info.getDisplayName();
165
    }
166
167
    @Override
168
    @CheckForNull
169
    public final Icon getProjectIcon() {
170
        final ProjectInformation info = getProjectInfo();
171
        return info == null ?
172
            null :
173
            info.getIcon();
174
    }
175
176
    @Override
177
    public final int getOffset() {
178
        //todo: fixme
179
        return -1;
180
    }
181
182
    @NonNull
183
    final FileObject getRoot() {
184
        return root;
185
    }
186
187
    @NonNull
188
    final ElementHandle<TypeElement> getOwner() {
189
        return owner;
190
    }
191
192
    @CheckForNull
193
    private ProjectInformation getProjectInfo() {
194
        return project == null ?
195
            null :
196
            project.getLookup().lookup(ProjectInformation.class);   //Intentionally does not use ProjectUtils.getInformation() it does project icon annotation which is expensive
197
    }
198
}
(-)a/java.sourceui/src/org/netbeans/modules/java/source/ui/JavaSymbolProvider.java (-63 / +6 lines)
Lines 230-297 Link Here
230
                                final Map<ElementHandle<TypeElement>,Set<String>> r = new HashMap<>();
230
                                final Map<ElementHandle<TypeElement>,Set<String>> r = new HashMap<>();
231
                                impl.getDeclaredElements(ident, kind, DocumentUtil.elementHandleConvertor(),r);
231
                                impl.getDeclaredElements(ident, kind, DocumentUtil.elementHandleConvertor(),r);
232
                                if (!r.isEmpty()) {
232
                                if (!r.isEmpty()) {
233
                                    //Needs FileManagerTransaction as it creates CPI with backgroundCompilation == true
233
                                    for (final Map.Entry<ElementHandle<TypeElement>,Set<String>> p : r.entrySet()) {
234
                                    TransactionContext.
234
                                        final ElementHandle<TypeElement> owner = p.getKey();
235
                                            beginTrans().
235
                                        for (String symbol : p.getValue()) {
236
                                            register(FileManagerTransaction.class, FileManagerTransaction.read()).
236
                                            result.addResult(new AsyncJavaSymbolDescriptor(project, root, impl, owner, symbol));
237
                                            register(ProcessorGenerated.class, ProcessorGenerated.nullWrite());
237
                                        }
238
                                    try {
239
                                        final ClasspathInfo cpInfo = ClasspathInfoAccessor.getINSTANCE().create(root,null,true,true,false,false);
240
                                        final JavaSource js = JavaSource.create(cpInfo);
241
                                        js.runUserActionTask(new Task<CompilationController>() {
242
                                            @Override
243
                                            public void run (final CompilationController controller) {
244
                                                for (final Map.Entry<ElementHandle<TypeElement>,Set<String>> p : r.entrySet()) {
245
                                                    final ElementHandle<TypeElement> owner = p.getKey();
246
                                                    final TypeElement te = owner.resolve(controller);
247
                                                    final Set<String> idents = p.getValue();
248
                                                    if (te != null) {
249
                                                        if (idents.contains(getSimpleName(te, null)) && matchesRestrictions(te, restriction)) {
250
                                                            result.addResult(new JavaSymbolDescriptor(
251
                                                                    te.getSimpleName().toString(),
252
                                                                    null,
253
                                                                    te.getKind(),
254
                                                                    te.getModifiers(),
255
                                                                    owner,
256
                                                                    ElementHandle.create(te),
257
                                                                    project,
258
                                                                    root,
259
                                                                    impl));
260
                                                        }
261
                                                        for (Element ne : te.getEnclosedElements()) {
262
                                                            if (idents.contains(getSimpleName(ne, te)) && matchesRestrictions(ne, restriction)) {
263
                                                                final Pair<String,String> name = getDisplayName(ne, te);
264
                                                                result.addResult(new JavaSymbolDescriptor(
265
                                                                    name.first(),
266
                                                                    name.second(),
267
                                                                    ne.getKind(),
268
                                                                    ne.getModifiers(),
269
                                                                    owner,
270
                                                                    ElementHandle.create(ne),
271
                                                                    project,
272
                                                                    root,
273
                                                                    impl));
274
                                                            }
275
                                                        }
276
                                                    }
277
                                                }
278
                                            }
279
280
                                            private String getSimpleName (
281
                                                    @NonNull final Element element,
282
                                                    @NullAllowed final Element enclosingElement) {
283
                                                String result = element.getSimpleName().toString();
284
                                                if (enclosingElement != null && INIT.equals(result)) {
285
                                                    result = enclosingElement.getSimpleName().toString();
286
                                                }
287
                                                if (!caseSensitive) {
288
                                                    result = result.toLowerCase();
289
                                                }
290
                                                return result;
291
                                            }
292
                                        },true);
293
                                    } finally {
294
                                        TransactionContext.get().commit();
295
                                    }
238
                                    }
296
                                }
239
                                }
297
240
Lines 352-358 Link Here
352
    }
295
    }
353
296
354
    @NonNull
297
    @NonNull
355
    private static Pair<String,String> getDisplayName (
298
    static Pair<String,String> getDisplayName (
356
            @NonNull final Element e,
299
            @NonNull final Element e,
357
            @NonNull final Element enclosingElement) {
300
            @NonNull final Element enclosingElement) {
358
        assert e != null;
301
        assert e != null;
(-)a/java.sourceui/src/org/netbeans/modules/java/source/ui/JavaSymbolDescriptor.java (-132 / +5 lines)
Lines 42-119 Link Here
42
42
43
package org.netbeans.modules.java.source.ui;
43
package org.netbeans.modules.java.source.ui;
44
44
45
import java.io.File;
46
import java.io.IOException;
47
import java.net.URL;
48
import java.util.Set;
45
import java.util.Set;
49
import javax.lang.model.element.ElementKind;
46
import javax.lang.model.element.ElementKind;
50
import javax.lang.model.element.Modifier;
47
import javax.lang.model.element.Modifier;
51
import javax.lang.model.element.TypeElement;
52
import javax.swing.Icon;
48
import javax.swing.Icon;
53
import org.netbeans.api.annotations.common.CheckForNull;
54
import org.netbeans.api.annotations.common.NonNull;
49
import org.netbeans.api.annotations.common.NonNull;
55
import org.netbeans.api.annotations.common.NullAllowed;
50
import org.netbeans.api.annotations.common.NullAllowed;
56
import org.netbeans.api.java.classpath.ClassPath;
57
import org.netbeans.api.java.source.ClasspathInfo;
51
import org.netbeans.api.java.source.ClasspathInfo;
58
import org.netbeans.api.java.source.ElementHandle;
52
import org.netbeans.api.java.source.ElementHandle;
59
import org.netbeans.api.java.source.SourceUtils;
60
import org.netbeans.api.java.source.ui.ElementOpen;
53
import org.netbeans.api.java.source.ui.ElementOpen;
61
import org.netbeans.api.project.Project;
62
import org.netbeans.api.project.ProjectInformation;
63
import org.netbeans.api.project.ProjectUtils;
64
import org.netbeans.modules.java.source.parsing.FileObjects;
65
import org.netbeans.modules.java.source.usages.ClassIndexImpl;
66
import org.netbeans.modules.java.ui.Icons;
54
import org.netbeans.modules.java.ui.Icons;
67
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
68
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
69
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
70
import org.openide.filesystems.FileUtil;
71
import org.openide.util.Exceptions;
72
56
73
/**
57
/**
74
 *
58
 *
75
 * @author Tomas Zezula
59
 * @author Tomas Zezula
76
 */
60
 */
77
public class JavaSymbolDescriptor extends SymbolDescriptor {
61
final class ResolvedJavaSymbolDescriptor extends JavaSymbolDescriptorBase {
78
62
79
    private final String simpleName;
63
    private final String simpleName;
80
    private final String simpleNameSuffix;
64
    private final String simpleNameSuffix;
81
    private final ElementHandle<TypeElement> owner;
82
    private final ElementHandle<?> me;
65
    private final ElementHandle<?> me;
83
    private final ElementKind kind;
66
    private final ElementKind kind;
84
    private final Set<Modifier> modifiers;
67
    private final Set<Modifier> modifiers;
85
    private final FileObject root;
86
    private final Project project;
87
    private final ClassIndexImpl ci;
88
    private FileObject cachedFo;
89
    private volatile String cachedPath;
90
68
91
    public JavaSymbolDescriptor (
69
    ResolvedJavaSymbolDescriptor (
70
            @NonNull final JavaSymbolDescriptorBase base,
92
            @NonNull final String simpleName,
71
            @NonNull final String simpleName,
93
            @NullAllowed final String simpleNameSuffix,
72
            @NullAllowed final String simpleNameSuffix,
94
            @NonNull final ElementKind kind,
73
            @NonNull final ElementKind kind,
95
            @NonNull final Set<Modifier> modifiers,
74
            @NonNull final Set<Modifier> modifiers,
96
            @NonNull final ElementHandle<TypeElement> owner,
75
            @NonNull final ElementHandle<?> me) {
97
            @NonNull final ElementHandle<?> me,
76
        super(base);
98
            @NullAllowed final Project project,
99
            @NonNull final FileObject root,
100
            @NonNull final ClassIndexImpl ci) {
101
        assert simpleName != null;
77
        assert simpleName != null;
102
        assert kind != null;
78
        assert kind != null;
103
        assert modifiers != null;
79
        assert modifiers != null;
104
        assert owner != null;
105
        assert me != null;
80
        assert me != null;
106
        assert root != null;
107
        assert ci != null;
108
        this.simpleName = simpleName;
81
        this.simpleName = simpleName;
109
        this.simpleNameSuffix = simpleNameSuffix;
82
        this.simpleNameSuffix = simpleNameSuffix;
110
        this.kind = kind;
83
        this.kind = kind;
111
        this.modifiers = modifiers;
84
        this.modifiers = modifiers;
112
        this.owner = owner;
113
        this.me = me;
85
        this.me = me;
114
        this.root = root;
115
        this.project = project;
116
        this.ci = ci;
117
    }
86
    }
118
87
119
    @Override
88
    @Override
Lines 134-195 Link Here
134
    }
103
    }
135
104
136
    @Override
105
    @Override
137
    public String getOwnerName() {
138
        return owner.getQualifiedName();
139
    }
140
141
142
    @Override
143
    public FileObject getFileObject() {
144
        if (cachedFo == null) {
145
            final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPath.EMPTY,
146
                    ClassPath.EMPTY, ClassPathSupport.createClassPath(root));
147
            cachedFo = SourceUtils.getFile(owner, cpInfo);
148
        }
149
        return cachedFo;
150
    }
151
152
    @Override
153
    @NonNull
154
    public String getFileDisplayPath() {
155
        String res = cachedPath;
156
        if (res == null) {
157
            final File rootFile = FileUtil.toFile(root);
158
            if (rootFile != null) {
159
                try {
160
                    final String binaryName = owner.getBinaryName();
161
                    String relativePath = ci.getSourceName(binaryName);
162
                    if (relativePath == null) {
163
                        relativePath = binaryName;
164
                        int lastDot = relativePath.lastIndexOf('.');    //NOI18N
165
                        int csIndex = relativePath.indexOf('$', lastDot);     //NOI18N
166
                        if (csIndex > 0 && csIndex < relativePath.length()-1) {
167
                            relativePath = binaryName.substring(0, csIndex);
168
                        }
169
                        relativePath = String.format(
170
                            "%s.%s",    //NOI18N
171
                            FileObjects.convertPackage2Folder(relativePath, File.separatorChar),
172
                            FileObjects.JAVA);
173
                    }
174
                    res = new File (rootFile, relativePath).getAbsolutePath();
175
                } catch (IOException | InterruptedException e) {
176
                    Exceptions.printStackTrace(e);
177
                }
178
            }
179
            if (res == null) {
180
                final FileObject fo = getFileObject();
181
                res = fo == null ?
182
                    "" :    //NOI18N
183
                    FileUtil.getFileDisplayName(fo);
184
            }
185
            cachedPath = res;
186
        }
187
        return res;
188
    }
189
190
191
192
    @Override
193
    public void open() {
106
    public void open() {
194
        FileObject file = getFileObject();
107
        FileObject file = getFileObject();
195
        if (file != null) {
108
        if (file != null) {
Lines 198-241 Link Here
198
	    ElementOpen.open(cpInfo, me);
111
	    ElementOpen.open(cpInfo, me);
199
        }
112
        }
200
    }
113
    }
201
202
    @Override
203
    public String getProjectName() {
204
        final ProjectInformation info = getProjectInfo();
205
        return info == null ?
206
            "" :    //NOI18N
207
            info.getDisplayName();
208
    }
209
210
    @Override
211
    public Icon getProjectIcon() {
212
        final ProjectInformation info = getProjectInfo();
213
        return info == null ?
214
            null :
215
            info.getIcon();
216
    }
217
218
    @Override
219
    public int getOffset() {
220
        //todo: fixme
221
        return -1;
222
    }
223
224
    @NonNull
225
    public ElementKind getElementKind() {
226
        return kind;
227
    }
228
229
    @NonNull
230
    public Set<? extends Modifier> getModifiers() {
231
        return modifiers;
232
    }
233
234
    @CheckForNull
235
    private ProjectInformation getProjectInfo() {
236
        return project == null ?
237
            null :
238
            project.getLookup().lookup(ProjectInformation.class);   //Intentionally does not use ProjectUtils.getInformation() it does project icon annotation which is expensive
239
    }
240
241
}
114
}
(-)a/jumpto/src/org/netbeans/modules/jumpto/symbol/ContentProviderImpl.java (-7 / +21 lines)
Lines 48-54 Link Here
48
import java.util.Collection;
48
import java.util.Collection;
49
import java.util.Collections;
49
import java.util.Collections;
50
import java.util.IdentityHashMap;
50
import java.util.IdentityHashMap;
51
import java.util.LinkedHashSet;
52
import java.util.List;
51
import java.util.List;
53
import java.util.Set;
52
import java.util.Set;
54
import java.util.concurrent.Callable;
53
import java.util.concurrent.Callable;
Lines 65-76 Link Here
65
import javax.swing.SwingUtilities;
64
import javax.swing.SwingUtilities;
66
import org.netbeans.api.annotations.common.CheckForNull;
65
import org.netbeans.api.annotations.common.CheckForNull;
67
import org.netbeans.api.annotations.common.NonNull;
66
import org.netbeans.api.annotations.common.NonNull;
68
import org.netbeans.api.annotations.common.NullAllowed;
69
import org.netbeans.modules.jumpto.common.AbstractModelFilter;
67
import org.netbeans.modules.jumpto.common.AbstractModelFilter;
70
import org.netbeans.modules.jumpto.common.CurrentSearch;
68
import org.netbeans.modules.jumpto.common.CurrentSearch;
69
import org.netbeans.modules.jumpto.common.Factory;
71
import org.netbeans.modules.jumpto.common.ItemRenderer;
70
import org.netbeans.modules.jumpto.common.ItemRenderer;
72
import org.netbeans.modules.jumpto.common.Models;
71
import org.netbeans.modules.jumpto.common.Models;
73
import org.netbeans.modules.jumpto.common.Utils;
72
import org.netbeans.modules.jumpto.common.Utils;
73
import org.netbeans.spi.jumpto.support.AsyncDescriptor;
74
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
74
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
75
import org.netbeans.spi.jumpto.symbol.SymbolProvider;
75
import org.netbeans.spi.jumpto.symbol.SymbolProvider;
76
import org.netbeans.spi.jumpto.type.SearchType;
76
import org.netbeans.spi.jumpto.type.SearchType;
Lines 272-278 Link Here
272
272
273
        @Override
273
        @Override
274
        public String getHighlightText(@NonNull final SymbolDescriptor item) {
274
        public String getHighlightText(@NonNull final SymbolDescriptor item) {
275
            return SymbolProviderAccessor.DEFAULT.getHighlightText(item);
275
            return SymbolProviderAccessor.DEFAULT.getHighlightText(
276
                    RefreshableSymbolDescriptor.unwrap(item));
276
        }
277
        }
277
278
278
        @Override
279
        @Override
Lines 362-370 Link Here
362
                    lastSize = newSize[0];
363
                    lastSize = newSize[0];
363
                    lastProvCount = newProvCount;
364
                    lastProvCount = newProvCount;
364
                    Collections.sort(mergedSymbols, new SymbolComparator());
365
                    Collections.sort(mergedSymbols, new SymbolComparator());
365
                    final ListModel fmodel = Models.fromList(
366
                    final ListModel fmodel = Models.refreshable(
366
                            mergedSymbols,
367
                            Models.fromList(
367
                            currentSearch.resetFilter());
368
                                mergedSymbols,
369
                                currentSearch.resetFilter()),
370
                            new AsyncConvertor()
371
                    );
368
                    if ( isCanceled ) {
372
                    if ( isCanceled ) {
369
                        LOG.log(
373
                        LOG.log(
370
                            Level.FINE,
374
                            Level.FINE,
Lines 498-504 Link Here
498
        }
502
        }
499
    }
503
    }
500
504
501
    private static class Result {
505
    private static final class Result {
502
        final List<SymbolDescriptor> symbols;
506
        final List<SymbolDescriptor> symbols;
503
        final int retry;
507
        final int retry;
504
        final Collection<SymbolProvider> nonFinishedProviders;
508
        final Collection<SymbolProvider> nonFinishedProviders;
Lines 516-519 Link Here
516
                    this.nonFinishedProviders.isEmpty();
520
                    this.nonFinishedProviders.isEmpty();
517
        }
521
        }
518
    }
522
    }
523
524
    private static final class AsyncConvertor implements Factory<SymbolDescriptor, Pair<SymbolDescriptor,Runnable>> {
525
        @Override
526
        public SymbolDescriptor create(Pair<SymbolDescriptor, Runnable> p) {
527
            if (p.first() instanceof AsyncDescriptor) {
528
                return new RefreshableSymbolDescriptor(p.first(), p.second());
529
            }
530
            return p.first();
531
        }
532
    }
519
}
533
}
(-)a/jumpto/src/org/netbeans/modules/jumpto/symbol/RefreshableSymbolDescriptor.java (+150 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.jumpto.symbol;
43
44
import java.util.Collection;
45
import javax.swing.Icon;
46
import javax.swing.SwingUtilities;
47
import org.netbeans.api.annotations.common.CheckForNull;
48
import org.netbeans.api.annotations.common.NonNull;
49
import org.netbeans.api.annotations.common.NullAllowed;
50
import org.netbeans.spi.jumpto.support.AsyncDescriptor;
51
import org.netbeans.spi.jumpto.support.DescriptorChangeEvent;
52
import org.netbeans.spi.jumpto.support.DescriptorChangeListener;
53
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
54
import org.openide.filesystems.FileObject;
55
56
/**
57
 *
58
 * @author Tomas Zezula
59
 */
60
final class RefreshableSymbolDescriptor extends SymbolDescriptor implements DescriptorChangeListener<SymbolDescriptor> {
61
62
    private final Runnable refreshCallback;
63
    private volatile SymbolDescriptor delegate;
64
65
    RefreshableSymbolDescriptor(
66
        @NonNull final SymbolDescriptor delegate,
67
        @NonNull final Runnable refreshCallback) {
68
        assert delegate != null;
69
        assert refreshCallback != null;
70
        this.delegate = delegate;
71
        this.refreshCallback = refreshCallback;
72
        if (delegate instanceof AsyncDescriptor) {
73
            ((AsyncDescriptor)delegate).addDescriptorChangeListener(this);
74
        } else {
75
            throw new IllegalArgumentException(String.format(
76
                    "The delegate: %s is not an AsyncDescriptor",   //NOI18N
77
                    delegate));
78
        }
79
    }
80
81
    @Override
82
    public Icon getIcon() {
83
        return delegate.getIcon();
84
    }
85
86
    @Override
87
    public String getSimpleName() {
88
        return delegate.getSimpleName();
89
    }
90
91
    @Override
92
    public String getSymbolName() {
93
        return delegate.getSymbolName();
94
    }
95
96
    @Override
97
    public String getOwnerName() {
98
        return delegate.getOwnerName();
99
    }
100
101
    @Override
102
    public String getProjectName() {
103
        return delegate.getProjectName();
104
    }
105
106
    @Override
107
    public Icon getProjectIcon() {
108
        return delegate.getProjectIcon();
109
    }
110
111
    @Override
112
    public FileObject getFileObject() {
113
        return delegate.getFileObject();
114
    }
115
116
    @Override
117
    public int getOffset() {
118
        return delegate.getOffset();
119
    }
120
121
    @Override
122
    public void open() {
123
        delegate.open();
124
    }
125
126
    @Override
127
    public void descriptorChanged(@NonNull final DescriptorChangeEvent<SymbolDescriptor> event) {
128
        final Collection<? extends SymbolDescriptor> symbols = event.getReplacement();
129
        if (!symbols.isEmpty()) {
130
            //Todo: fixme - size = 0 or size > 1
131
            delegate = symbols.iterator().next();
132
            runInEDT(this.refreshCallback);
133
        }
134
    }
135
136
    @CheckForNull
137
    static SymbolDescriptor unwrap (@NullAllowed final SymbolDescriptor desc) {
138
        return desc == null || desc.getClass() != RefreshableSymbolDescriptor.class ?
139
                desc :
140
                ((RefreshableSymbolDescriptor)desc).delegate;
141
    }
142
143
    private static void runInEDT(@NonNull final Runnable r) {
144
        if (SwingUtilities.isEventDispatchThread()) {
145
            r.run();
146
        } else {
147
            SwingUtilities.invokeLater(r);
148
        }
149
    }
150
}
(-)a/jumpto/src/org/netbeans/modules/jumpto/symbol/SymbolComparator.java (-1 / +10 lines)
Lines 42-47 Link Here
42
42
43
package org.netbeans.modules.jumpto.symbol;
43
package org.netbeans.modules.jumpto.symbol;
44
44
45
import org.netbeans.api.annotations.common.NonNull;
45
import org.netbeans.modules.jumpto.EntityComparator;
46
import org.netbeans.modules.jumpto.EntityComparator;
46
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
47
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
47
48
Lines 89-95 Link Here
89
            return result; // e1projectName NOT equals to e2projectName
90
            return result; // e1projectName NOT equals to e2projectName
90
        }
91
        }
91
        // here: e1projectName equals to e2projectName
92
        // here: e1projectName equals to e2projectName
92
        result = compare(e1.getSymbolName(), e2.getSymbolName());
93
        result = compare(getSortName(e1), getSortName(e2));
93
        if ( result != 0 ) {
94
        if ( result != 0 ) {
94
           return result;
95
           return result;
95
        }
96
        }
Lines 97-100 Link Here
97
        return compare(e1.getOwnerName(), e2.getOwnerName());
98
        return compare(e1.getOwnerName(), e2.getOwnerName());
98
    }
99
    }
99
100
101
    @NonNull
102
    private static String getSortName(@NonNull final SymbolDescriptor d) {
103
        String res = d.getSimpleName();
104
        if (res == null) {
105
            res = d.getSymbolName();
106
        }
107
        return res;
108
    }
100
}
109
}
(-)a/jumpto/src/org/netbeans/spi/jumpto/support/AsyncDescriptor.java (+53 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.jumpto.support;
43
44
import org.netbeans.api.annotations.common.NonNull;
45
46
/**
47
 *
48
 * @author Tomas Zezula
49
 */
50
public interface AsyncDescriptor<T> {
51
    void addDescriptorChangeListener(@NonNull DescriptorChangeListener<T> listener);
52
    void removeDescriptorChangeListener(@NonNull DescriptorChangeListener<T> listener);
53
}
(-)a/jumpto/src/org/netbeans/spi/jumpto/support/DescriptorChangeEvent.java (+70 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.jumpto.support;
43
44
import java.util.Collection;
45
import java.util.Collections;
46
import java.util.EventObject;
47
import org.netbeans.api.annotations.common.NonNull;
48
import org.openide.util.Parameters;
49
50
/**
51
 *
52
 * @author Tomas Zezula
53
 */
54
public final class DescriptorChangeEvent<T> extends EventObject {
55
56
    private final Collection<? extends T> replacement;
57
58
    public DescriptorChangeEvent(
59
            @NonNull final T source,
60
            @NonNull final Collection<? extends T> replacement) {
61
        super(source);
62
        Parameters.notNull("descriptors", replacement); //NOI18N
63
        this.replacement = Collections.unmodifiableCollection(replacement);
64
    }
65
66
    @NonNull
67
    public Collection<? extends T> getReplacement() {
68
        return replacement;
69
    }
70
}
(-)a/jumpto/src/org/netbeans/spi/jumpto/support/DescriptorChangeListener.java (+53 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.jumpto.support;
43
44
import java.util.EventListener;
45
import org.netbeans.api.annotations.common.NonNull;
46
47
/**
48
 *
49
 * @author Tomas Zezula
50
 */
51
public interface DescriptorChangeListener<T> extends EventListener {
52
    void descriptorChanged(@NonNull DescriptorChangeEvent<T> event);
53
}

Return to bug 248941