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 175998
Collapse All | Expand All

(-)a/java.sourceui/src/org/netbeans/modules/java/source/ui/JavaTypeProvider.java (-7 / +2 lines)
Lines 347-359 Link Here
347
                }
347
                }
348
348
349
                if (types.isEmpty() && scanInProgress) {
349
                if (types.isEmpty() && scanInProgress) {
350
                    try {
350
                    res.pendingResult();
351
                        synchronized (JavaTypeProvider.this) {
351
                    return;
352
                            this.wait(2000);
353
                        }
354
                    } catch (InterruptedException ex) {
355
                        Exceptions.printStackTrace(ex);
356
                    }
357
                }
352
                }
358
353
359
                if ( isCanceled ) {
354
                if ( isCanceled ) {
(-)a/jumpto/apichanges.xml (+16 lines)
Lines 121-126 Link Here
121
            <issue number="138345"/>
121
            <issue number="138345"/>
122
        </change>                
122
        </change>                
123
123
124
        <change id="(Provider.Result.pendingResult">
125
            <api name="general"/>
126
            <summary>Added method (Type|Symbol)Provider.Result.pendingResult()</summary>
127
            <version major="1" minor="14"/>
128
            <date day="4" month="11" year="2009"/>
129
            <author login="pflaska"/>
130
            <compatibility addition="yes"/>
131
            <description>
132
                Added method TypeProvider.Result.pendingResult() and
133
                SymbolProvider.Result.pendingResult()  to notify 
134
                provider's caller that the provider should be called again.
135
            </description>
136
            <issue number="175998"/>
137
        </change>
138
        
139
    </changes>
124
    <!-- Now the surrounding HTML text and document structure: -->
140
    <!-- Now the surrounding HTML text and document structure: -->
125
141
126
    <htmlcontents>
142
    <htmlcontents>
(-)a/jumpto/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.netbeans.modules.jumpto/1
2
OpenIDE-Module: org.netbeans.modules.jumpto/1
3
OpenIDE-Module-Layer: org/netbeans/modules/jumpto/resources/layer.xml
3
OpenIDE-Module-Layer: org/netbeans/modules/jumpto/resources/layer.xml
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jumpto/resources/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jumpto/resources/Bundle.properties
5
OpenIDE-Module-Specification-Version: 1.13
5
OpenIDE-Module-Specification-Version: 1.14
6
AutoUpdate-Show-In-Client: false
6
AutoUpdate-Show-In-Client: false
(-)a/jumpto/src/org/netbeans/modules/jumpto/symbol/SymbolProviderAccessor.java (+3 lines)
Lines 45-50 Link Here
45
import org.netbeans.spi.jumpto.symbol.SymbolProvider;
45
import org.netbeans.spi.jumpto.symbol.SymbolProvider;
46
import org.netbeans.spi.jumpto.type.SearchType;
46
import org.netbeans.spi.jumpto.type.SearchType;
47
import org.openide.util.Exceptions;
47
import org.openide.util.Exceptions;
48
import static org.netbeans.spi.jumpto.symbol.SymbolProvider.*;
48
49
49
/**
50
/**
50
 *
51
 *
Lines 65-68 Link Here
65
    public abstract SymbolProvider.Context createContext(Project p, String text, SearchType t);
66
    public abstract SymbolProvider.Context createContext(Project p, String text, SearchType t);
66
67
67
    public abstract SymbolProvider.Result createResult(List<? super SymbolDescriptor> result, String[] message);
68
    public abstract SymbolProvider.Result createResult(List<? super SymbolDescriptor> result, String[] message);
69
70
    public abstract int getRetry(Result result);
68
}
71
}
(-)a/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java (-39 / +53 lines)
Lines 397-441 Link Here
397
        }
397
        }
398
398
399
        public void run() {
399
        public void run() {
400
            Profile profile = initializeProfiling();
400
            for (;;) {
401
            try {
401
                final int[] retry = new int[1];
402
                LOGGER.fine( "Worker for " + text + " - started " + ( System.currentTimeMillis() - createTime ) + " ms."  );
403
402
404
                final List<? extends TypeDescriptor> types = getTypeNames( text );
403
                Profile profile = initializeProfiling();
405
                if ( isCanceled ) {
404
                try {
406
                    LOGGER.fine( "Worker for " + text + " exited after cancel " + ( System.currentTimeMillis() - createTime ) + " ms."  );
405
                    LOGGER.fine( "Worker for " + text + " - started " + ( System.currentTimeMillis() - createTime ) + " ms."  );
406
407
                    final List<? extends TypeDescriptor> types = getTypeNames(text, retry);
408
                    if ( isCanceled ) {
409
                        LOGGER.fine( "Worker for " + text + " exited after cancel " + ( System.currentTimeMillis() - createTime ) + " ms."  );
410
                        return;
411
                    }
412
                    ListModel model = Models.fromList(types);
413
                    if (typeFilter != null) {
414
                        model = LazyListModel.create(model, GoToTypeAction.this, 0.1, "Not computed yet");
415
                    }
416
                    final ListModel fmodel = model;
417
                    if ( isCanceled ) {
418
                        LOGGER.fine( "Worker for " + text + " exited after cancel " + ( System.currentTimeMillis() - createTime ) + " ms."  );
419
                        return;
420
                    }
421
422
                    if ( !isCanceled && fmodel != null ) {
423
                        LOGGER.fine( "Worker for text " + text + " finished after " + ( System.currentTimeMillis() - createTime ) + " ms."  );
424
                        SwingUtilities.invokeLater(new Runnable() {
425
                            public void run() {
426
                                panel.setModel(fmodel);
427
                                if (okButton != null && !types.isEmpty()) {
428
                                    okButton.setEnabled (true);
429
                                }
430
                            }
431
                        });
432
                    }
433
                } finally {
434
                    if (profile != null) {
435
                        try {
436
                            profile.stop();
437
                        } catch (Exception ex) {
438
                            LOGGER.log(Level.INFO, "Cannot stop profiling", ex);
439
                        }
440
                    }
441
                }
442
443
                if (retry[0] > 0) {
444
                    try {
445
                        Thread.sleep(retry[0]);
446
                    } catch (InterruptedException ex) {
447
                        Exceptions.printStackTrace(ex);
448
                    }
449
                } else {
407
                    return;
450
                    return;
408
                }
451
                }
409
                ListModel model = Models.fromList(types);
452
            } // for
410
                if (typeFilter != null) {
411
                    model = LazyListModel.create(model, GoToTypeAction.this, 0.1, "Not computed yet");
412
                }
413
                final ListModel fmodel = model;
414
                if ( isCanceled ) {
415
                    LOGGER.fine( "Worker for " + text + " exited after cancel " + ( System.currentTimeMillis() - createTime ) + " ms."  );
416
                    return;
417
                }
418
419
                if ( !isCanceled && fmodel != null ) {
420
                    LOGGER.fine( "Worker for text " + text + " finished after " + ( System.currentTimeMillis() - createTime ) + " ms."  );
421
                    SwingUtilities.invokeLater(new Runnable() {
422
                        public void run() {
423
                            panel.setModel(fmodel);
424
                            if (okButton != null && !types.isEmpty()) {
425
                                okButton.setEnabled (true);
426
                            }
427
                        }
428
                    });
429
                }
430
            } finally {
431
                if (profile != null) {
432
                    try {
433
                        profile.stop();
434
                    } catch (Exception ex) {
435
                        LOGGER.log(Level.INFO, "Cannot stop profiling", ex);
436
                    }
437
                }
438
            }
439
        }
453
        }
440
        
454
        
441
        public void cancel() {
455
        public void cancel() {
Lines 453-459 Link Here
453
        }
467
        }
454
468
455
        @SuppressWarnings("unchecked")
469
        @SuppressWarnings("unchecked")
456
        private List<? extends TypeDescriptor> getTypeNames(String text) {
470
        private List<? extends TypeDescriptor> getTypeNames(String text, int[] retry) {
457
            // TODO: Search twice, first for current project, then for all projects
471
            // TODO: Search twice, first for current project, then for all projects
458
            List<TypeDescriptor> items;
472
            List<TypeDescriptor> items;
459
            // Multiple providers: merge results
473
            // Multiple providers: merge results
Lines 478-485 Link Here
478
                }
492
                }
479
                long delta = System.currentTimeMillis() - start;
493
                long delta = System.currentTimeMillis() - start;
480
                LOGGER.fine("Provider '" + provider.getDisplayName() + "' took " + delta + " ms.");
494
                LOGGER.fine("Provider '" + provider.getDisplayName() + "' took " + delta + " ms.");
481
                
482
            }
495
            }
496
            retry[0] = TypeProviderAccessor.DEFAULT.getRetry(result);
483
            if ( !isCanceled ) {   
497
            if ( !isCanceled ) {   
484
                //time = System.currentTimeMillis();
498
                //time = System.currentTimeMillis();
485
                Collections.sort(items, new TypeComparator());
499
                Collections.sort(items, new TypeComparator());
Lines 526-532 Link Here
526
    final void waitSearchFinished() {
540
    final void waitSearchFinished() {
527
        task.waitFinished();
541
        task.waitFinished();
528
    }
542
    }
529
    
543
530
    private static class Renderer extends DefaultListCellRenderer implements ChangeListener {
544
    private static class Renderer extends DefaultListCellRenderer implements ChangeListener {
531
         
545
         
532
        private MyPanel rendererComponent;
546
        private MyPanel rendererComponent;
(-)a/jumpto/src/org/netbeans/modules/jumpto/type/TypeProviderAccessor.java (+2 lines)
Lines 64-67 Link Here
64
    public abstract Context createContext(Project p, String text, SearchType t);
64
    public abstract Context createContext(Project p, String text, SearchType t);
65
65
66
    public abstract Result createResult(List<? super TypeDescriptor> result, String[] message);
66
    public abstract Result createResult(List<? super TypeDescriptor> result, String[] message);
67
68
    public abstract int getRetry(Result result);
67
}
69
}
(-)a/jumpto/src/org/netbeans/spi/jumpto/symbol/SymbolProvider.java (-1 / +22 lines)
Lines 135-141 Link Here
135
                @Override
135
                @Override
136
                public Result createResult(List<? super SymbolDescriptor> result, String[] message) {
136
                public Result createResult(List<? super SymbolDescriptor> result, String[] message) {
137
                    return new Result(result, message);
137
                    return new Result(result, message);
138
                }            
138
                }
139
140
                @Override
141
                public int getRetry(Result result) {
142
                    return result.retry;
143
                }
144
145
139
            };
146
            };
140
        }
147
        }
141
        
148
        
Lines 179-184 Link Here
179
        
186
        
180
        private List<? super SymbolDescriptor> result;
187
        private List<? super SymbolDescriptor> result;
181
        private String[] message;
188
        private String[] message;
189
        private int retry;
182
190
183
        Result(List<? super SymbolDescriptor> result, String[] message) {
191
        Result(List<? super SymbolDescriptor> result, String[] message) {
184
            this.result = result;
192
            this.result = result;
Lines 213-218 Link Here
213
        public void addResult(List<? extends SymbolDescriptor> symbolDescriptor) {
221
        public void addResult(List<? extends SymbolDescriptor> symbolDescriptor) {
214
            ((List)result).addAll(symbolDescriptor);    //workaround javac issue http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6507334 
222
            ((List)result).addAll(symbolDescriptor);    //workaround javac issue http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6507334 
215
        }
223
        }
224
225
        /**
226
         * Notify caller that a provider should be called again because
227
         * of incomplete or inaccurate results.
228
         *
229
         * Method can be used when long running task blocks the provider
230
         * to complete the data.
231
         *
232
         * @since 1.14
233
         */
234
        public void pendingResult() {
235
            retry = 2000;
236
        }
216
    }
237
    }
217
238
218
}
239
}
(-)a/jumpto/src/org/netbeans/spi/jumpto/type/TypeProvider.java (+19 lines)
Lines 138-143 Link Here
138
                public Result createResult(List<? super TypeDescriptor> result, String[] message) {
138
                public Result createResult(List<? super TypeDescriptor> result, String[] message) {
139
                    return new Result(result, message);
139
                    return new Result(result, message);
140
                }
140
                }
141
142
                @Override
143
                public int getRetry(Result result) {
144
                    return result.retry;
145
                }
141
            };
146
            };
142
        }
147
        }
143
        
148
        
Lines 182-187 Link Here
182
        
187
        
183
        private List<? super TypeDescriptor> result;
188
        private List<? super TypeDescriptor> result;
184
        private String[] message;
189
        private String[] message;
190
        private int retry;
185
191
186
        Result(List<? super TypeDescriptor> result, String[] message) {
192
        Result(List<? super TypeDescriptor> result, String[] message) {
187
            this.result = result;
193
            this.result = result;
Lines 216-221 Link Here
216
        public void addResult(List<? extends TypeDescriptor> typeDescriptor) {
222
        public void addResult(List<? extends TypeDescriptor> typeDescriptor) {
217
            ((List)result).addAll(typeDescriptor);  //workaround javac issue http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6507334
223
            ((List)result).addAll(typeDescriptor);  //workaround javac issue http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6507334
218
        }
224
        }
225
226
        /**
227
         * Notify caller that a provider should be called again because
228
         * of incomplete or inaccurate results.
229
         *
230
         * Method can be used when long running task blocks the provider
231
         * to complete the data.
232
         * 
233
         * @since 1.14
234
         */
235
        public void pendingResult() {
236
            retry = 2000;
237
        }
219
    }
238
    }
220
239
221
}
240
}
(-)a/jumpto/test/unit/src/org/netbeans/modules/jumpto/type/GoToTypeActionTest.java (-1 / +11 lines)
Lines 69-74 Link Here
69
        action.waitSearchFinished();
69
        action.waitSearchFinished();
70
        assertEquals("Provider queried once", 1, TestTypeProvider.count);
70
        assertEquals("Provider queried once", 1, TestTypeProvider.count);
71
    }
71
    }
72
73
    public void testPendingResults() throws IOException {
74
        TestTypeProvider.count = 10;
75
        GoToTypeAction action = new GoToTypeAction();
76
        TypeDescriptor desc = action.getSelectedType(false);
77
        panel = action.panel;
78
        panel.nameField.setText("Pepik");
79
        action.waitSearchFinished();
80
        assertEquals("Provider queried once", 12, TestTypeProvider.count);
81
    }
72
    
82
    
73
    @Override
83
    @Override
74
    protected void tearDown() throws Exception {
84
    protected void tearDown() throws Exception {
Lines 90-96 Link Here
90
            final String text = panel.messageLabel.getText();
100
            final String text = panel.messageLabel.getText();
91
            assertTrue(text, text.startsWith("Searching"));
101
            assertTrue(text, text.startsWith("Searching"));
92
            count++;
102
            count++;
93
//SPI            if (count == 1) result.pendingResult();
103
            if (count == 10) result.pendingResult();
94
        }
104
        }
95
105
96
        public void cancel() {
106
        public void cancel() {

Return to bug 175998