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 (-41 / +148 lines)
Lines 44-136 Link Here
44
44
45
import java.io.File;
45
import java.io.File;
46
import java.io.IOException;
46
import java.io.IOException;
47
import java.net.URL;
48
import java.util.Set;
47
import java.util.Set;
48
import java.util.concurrent.atomic.AtomicReference;
49
import javax.lang.model.element.Element;
49
import javax.lang.model.element.ElementKind;
50
import javax.lang.model.element.ElementKind;
50
import javax.lang.model.element.Modifier;
51
import javax.lang.model.element.Modifier;
51
import javax.lang.model.element.TypeElement;
52
import javax.lang.model.element.TypeElement;
52
import javax.swing.Icon;
53
import javax.swing.Icon;
54
import javax.swing.event.ChangeListener;
53
import org.netbeans.api.annotations.common.CheckForNull;
55
import org.netbeans.api.annotations.common.CheckForNull;
54
import org.netbeans.api.annotations.common.NonNull;
56
import org.netbeans.api.annotations.common.NonNull;
55
import org.netbeans.api.annotations.common.NullAllowed;
57
import org.netbeans.api.annotations.common.NullAllowed;
56
import org.netbeans.api.java.classpath.ClassPath;
58
import org.netbeans.api.java.classpath.ClassPath;
57
import org.netbeans.api.java.source.ClasspathInfo;
59
import org.netbeans.api.java.source.ClasspathInfo;
60
import org.netbeans.api.java.source.CompilationController;
58
import org.netbeans.api.java.source.ElementHandle;
61
import org.netbeans.api.java.source.ElementHandle;
62
import org.netbeans.api.java.source.JavaSource;
59
import org.netbeans.api.java.source.SourceUtils;
63
import org.netbeans.api.java.source.SourceUtils;
64
import org.netbeans.api.java.source.Task;
60
import org.netbeans.api.java.source.ui.ElementOpen;
65
import org.netbeans.api.java.source.ui.ElementOpen;
61
import org.netbeans.api.project.Project;
66
import org.netbeans.api.project.Project;
62
import org.netbeans.api.project.ProjectInformation;
67
import org.netbeans.api.project.ProjectInformation;
63
import org.netbeans.api.project.ProjectUtils;
68
import org.netbeans.modules.java.source.indexing.TransactionContext;
69
import org.netbeans.modules.java.source.parsing.FileManagerTransaction;
64
import org.netbeans.modules.java.source.parsing.FileObjects;
70
import org.netbeans.modules.java.source.parsing.FileObjects;
71
import org.netbeans.modules.java.source.parsing.ProcessorGenerated;
65
import org.netbeans.modules.java.source.usages.ClassIndexImpl;
72
import org.netbeans.modules.java.source.usages.ClassIndexImpl;
73
import org.netbeans.modules.java.source.usages.ClasspathInfoAccessor;
66
import org.netbeans.modules.java.ui.Icons;
74
import org.netbeans.modules.java.ui.Icons;
67
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
75
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
76
import org.netbeans.spi.jumpto.support.AsyncDescriptor;
68
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
77
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
69
import org.openide.filesystems.FileObject;
78
import org.openide.filesystems.FileObject;
70
import org.openide.filesystems.FileUtil;
79
import org.openide.filesystems.FileUtil;
80
import org.openide.util.ChangeSupport;
71
import org.openide.util.Exceptions;
81
import org.openide.util.Exceptions;
82
import org.openide.util.Pair;
83
import org.openide.util.RequestProcessor;
72
84
73
/**
85
/**
74
 *
86
 *
75
 * @author Tomas Zezula
87
 * @author Tomas Zezula
76
 */
88
 */
77
public class JavaSymbolDescriptor extends SymbolDescriptor {
89
public class AsyncJavaSymbolDescriptor extends SymbolDescriptor implements AsyncDescriptor {
78
90
79
    private final String simpleName;
91
    private static final RequestProcessor WORKER = new RequestProcessor(AsyncJavaSymbolDescriptor.class);
80
    private final String simpleNameSuffix;
92
    private static final String INIT = "<init>"; //NOI18N
93
81
    private final ElementHandle<TypeElement> owner;
94
    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;
95
    private final FileObject root;
86
    private final Project project;
96
    private final Project project;
87
    private final ClassIndexImpl ci;
97
    private final ClassIndexImpl ci;
98
    private final String ident;
99
    private final ChangeSupport changeSupport;
100
88
    private FileObject cachedFo;
101
    private FileObject cachedFo;
89
    private volatile String cachedPath;
102
    private volatile String cachedPath;
90
103
91
    public JavaSymbolDescriptor (
104
    private final AtomicReference<State> state;
92
            @NonNull final String simpleName,
105
    private String simpleName;
93
            @NullAllowed final String simpleNameSuffix,
106
    private String simpleNameSuffix;
94
            @NonNull final ElementKind kind,
107
    private ElementHandle<?> me;
95
            @NonNull final Set<Modifier> modifiers,
108
    private ElementKind kind;
96
            @NonNull final ElementHandle<TypeElement> owner,
109
    private Set<Modifier> modifiers;
97
            @NonNull final ElementHandle<?> me,
110
111
    public AsyncJavaSymbolDescriptor (
98
            @NullAllowed final Project project,
112
            @NullAllowed final Project project,
99
            @NonNull final FileObject root,
113
            @NonNull final FileObject root,
100
            @NonNull final ClassIndexImpl ci) {
114
            @NonNull final ClassIndexImpl ci,
101
        assert simpleName != null;
115
            @NonNull final ElementHandle<TypeElement> owner,
102
        assert kind != null;
116
            @NonNull final String ident) {
103
        assert modifiers != null;
104
        assert owner != null;
117
        assert owner != null;
105
        assert me != null;
106
        assert root != null;
118
        assert root != null;
107
        assert ci != null;
119
        assert ci != null;
108
        this.simpleName = simpleName;
120
        assert ident != null;
109
        this.simpleNameSuffix = simpleNameSuffix;
110
        this.kind = kind;
111
        this.modifiers = modifiers;
112
        this.owner = owner;
121
        this.owner = owner;
113
        this.me = me;
114
        this.root = root;
122
        this.root = root;
115
        this.project = project;
123
        this.project = project;
116
        this.ci = ci;
124
        this.ci = ci;
125
        this.ident = ident;
126
        this.changeSupport = new ChangeSupport(this);
127
        this.state = new AtomicReference<>(State.NEW);
117
    }
128
    }
118
129
119
    @Override
130
    @Override
120
    public Icon getIcon() {
131
    public Icon getIcon() {
121
        return Icons.getElementIcon(kind, modifiers);
132
        if (State.INITIALIZED == this.state.get()) {
133
            return Icons.getElementIcon(kind, modifiers);
134
        } else {
135
            initialize(false);
136
            return null;
137
        }
122
    }
138
    }
123
139
124
    @Override
140
    @Override
125
    public String getSymbolName() {
141
    public String getSymbolName() {
126
        return simpleNameSuffix == null ?
142
        if (State.INITIALIZED == this.state.get()) {
127
                simpleName :
143
            return simpleNameSuffix == null ?
128
                simpleName + simpleNameSuffix;
144
                    simpleName :
145
                    simpleName + simpleNameSuffix;
146
        } else {
147
            initialize(false);
148
            return ident;
149
        }
129
    }
150
    }
130
151
131
    @Override
152
    @Override
132
    public String getSimpleName() {
153
    public String getSimpleName() {
133
        return simpleName;
154
        if (State.INITIALIZED == this.state.get()) {
155
            return simpleName;
156
        } else {
157
            return ident;
158
        }
134
    }
159
    }
135
160
136
    @Override
161
    @Override
Lines 194-200 Link Here
194
        FileObject file = getFileObject();
219
        FileObject file = getFileObject();
195
        if (file != null) {
220
        if (file != null) {
196
	    ClasspathInfo cpInfo = ClasspathInfo.create(file);
221
	    ClasspathInfo cpInfo = ClasspathInfo.create(file);
197
222
            if (State.INITIALIZED != this.state.get()) {
223
                initialize(true);
224
            }
198
	    ElementOpen.open(cpInfo, me);
225
	    ElementOpen.open(cpInfo, me);
199
        }
226
        }
200
    }
227
    }
Lines 221-236 Link Here
221
        return -1;
248
        return -1;
222
    }
249
    }
223
250
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
251
    @CheckForNull
235
    private ProjectInformation getProjectInfo() {
252
    private ProjectInformation getProjectInfo() {
236
        return project == null ?
253
        return project == null ?
Lines 238-241 Link Here
238
            project.getLookup().lookup(ProjectInformation.class);   //Intentionally does not use ProjectUtils.getInformation() it does project icon annotation which is expensive
255
            project.getLookup().lookup(ProjectInformation.class);   //Intentionally does not use ProjectUtils.getInformation() it does project icon annotation which is expensive
239
    }
256
    }
240
257
258
    private void initialize(final boolean force) {
259
        if (force || state.compareAndSet(State.NEW, State.INITIALIZING)) {
260
            final Runnable action = new Resolver();
261
            if (force) {
262
                action.run();
263
            } else {
264
                WORKER.execute(action);
265
            }
266
        }
267
    }
268
269
    @Override
270
    public void addChangeListener(ChangeListener listener) {
271
        changeSupport.addChangeListener(listener);
272
    }
273
274
    @Override
275
    public void removeChangeListener(ChangeListener listener) {
276
        changeSupport.removeChangeListener(listener);
277
    }
278
279
    private final class Resolver implements Runnable {
280
281
        @Override
282
        public void run() {
283
            try {
284
                TransactionContext.
285
                    beginTrans().
286
                    register(FileManagerTransaction.class, FileManagerTransaction.read()).
287
                    register(ProcessorGenerated.class, ProcessorGenerated.nullWrite());
288
                try {
289
                    final ClasspathInfo cpInfo = ClasspathInfoAccessor.getINSTANCE().create(root,null,true,true,false,false);
290
                    final JavaSource js = JavaSource.create(cpInfo);
291
                    js.runUserActionTask(new Task<CompilationController>() {
292
                        @Override
293
                        public void run (final CompilationController controller) {
294
                            final TypeElement te = owner.resolve(controller);
295
                            if (te != null) {
296
                                if (ident.equals(getSimpleName(te, null)) /*TODO && matchesRestrictions(te, restriction)*/) {
297
                                    simpleName = te.getSimpleName().toString();
298
                                    simpleNameSuffix = null;
299
                                    kind = te.getKind();
300
                                    modifiers = te.getModifiers();
301
                                    me = ElementHandle.create(te);
302
                                    state.set(State.INITIALIZED);
303
                                    changeSupport.fireChange();
304
                                }
305
                                for (Element ne : te.getEnclosedElements()) {
306
                                    if (ident.equals(getSimpleName(ne, te)) /*TODO && matchesRestrictions(ne, restriction)*/) {
307
                                        final Pair<String,String> name = JavaSymbolProvider.getDisplayName(ne, te);
308
                                        simpleName = name.first();
309
                                        simpleNameSuffix = name.second();
310
                                        kind = ne.getKind();
311
                                        modifiers = ne.getModifiers();
312
                                        me = ElementHandle.create(ne);
313
                                        state.set(State.INITIALIZED);
314
                                        changeSupport.fireChange();
315
                                        break;
316
                                    }
317
                                }
318
                            }
319
                        }
320
                    }, true);
321
                }finally {
322
                    TransactionContext.get().commit();
323
                }
324
            } catch (IOException e) {
325
                Exceptions.printStackTrace(e);
326
            }
327
        }
328
329
        private String getSimpleName (
330
                @NonNull final Element element,
331
                @NullAllowed final Element enclosingElement) {
332
            String result = element.getSimpleName().toString();
333
            if (enclosingElement != null && INIT.equals(result)) {
334
                result = enclosingElement.getSimpleName().toString();
335
            }
336
//TODO            if (!caseSensitive) {
337
                result = result.toLowerCase();
338
//            }
339
            return result;
340
        }
341
    }
342
343
    private enum State {
344
        NEW,
345
        INITIALIZING,
346
        INITIALIZED
347
    }
241
}
348
}
(-)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/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 (+144 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 javax.swing.Icon;
45
import javax.swing.SwingUtilities;
46
import javax.swing.event.ChangeEvent;
47
import javax.swing.event.ChangeListener;
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.spi.jumpto.support.AsyncDescriptor;
52
import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
53
import org.openide.filesystems.FileObject;
54
55
/**
56
 *
57
 * @author Tomas Zezula
58
 */
59
final class RefreshableSymbolDescriptor extends SymbolDescriptor implements ChangeListener {
60
61
    private final SymbolDescriptor delegate;
62
    private final Runnable refreshCallback;
63
64
    RefreshableSymbolDescriptor(
65
        @NonNull final SymbolDescriptor delegate,
66
        @NonNull final Runnable refreshCallback) {
67
        assert delegate != null;
68
        assert refreshCallback != null;
69
        this.delegate = delegate;
70
        this.refreshCallback = refreshCallback;
71
        if (delegate instanceof AsyncDescriptor) {
72
            ((AsyncDescriptor)delegate).addChangeListener(this);
73
        } else {
74
            throw new IllegalArgumentException(String.format(
75
                    "The delegate: %s is not an AsyncDescriptor",   //NOI18N
76
                    delegate));
77
        }
78
    }
79
80
    @Override
81
    public Icon getIcon() {
82
        return delegate.getIcon();
83
    }
84
85
    @Override
86
    public String getSimpleName() {
87
        return delegate.getSimpleName();
88
    }
89
90
    @Override
91
    public String getSymbolName() {
92
        return delegate.getSymbolName();
93
    }
94
95
    @Override
96
    public String getOwnerName() {
97
        return delegate.getOwnerName();
98
    }
99
100
    @Override
101
    public String getProjectName() {
102
        return delegate.getProjectName();
103
    }
104
105
    @Override
106
    public Icon getProjectIcon() {
107
        return delegate.getProjectIcon();
108
    }
109
110
    @Override
111
    public FileObject getFileObject() {
112
        return delegate.getFileObject();
113
    }
114
115
    @Override
116
    public int getOffset() {
117
        return delegate.getOffset();
118
    }
119
120
    @Override
121
    public void open() {
122
        delegate.open();
123
    }
124
125
    @Override
126
    public void stateChanged(ChangeEvent e) {
127
        runInEDT(this.refreshCallback);
128
    }
129
130
    @CheckForNull
131
    static SymbolDescriptor unwrap (@NullAllowed final SymbolDescriptor desc) {
132
        return desc == null || desc.getClass() != RefreshableSymbolDescriptor.class ?
133
                desc :
134
                ((RefreshableSymbolDescriptor)desc).delegate;
135
    }
136
137
    private static void runInEDT(@NonNull final Runnable r) {
138
        if (SwingUtilities.isEventDispatchThread()) {
139
            r.run();
140
        } else {
141
            SwingUtilities.invokeLater(r);
142
        }
143
    }
144
}
(-)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 (+54 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 javax.swing.event.ChangeListener;
45
import org.netbeans.api.annotations.common.NonNull;
46
47
/**
48
 *
49
 * @author Tomas Zezula
50
 */
51
public interface AsyncDescriptor {
52
    void addChangeListener(@NonNull ChangeListener listener);
53
    void removeChangeListener(@NonNull ChangeListener listener);
54
}

Return to bug 248941