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

(-)a/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionDoc.java (-3 / +3 lines)
Lines 45-53 Link Here
45
package org.netbeans.modules.editor.java;
45
package org.netbeans.modules.editor.java;
46
46
47
import java.net.URL;
47
import java.net.URL;
48
import java.util.concurrent.Callable;
48
import javax.lang.model.element.Element;
49
import javax.lang.model.element.Element;
49
import javax.swing.Action;
50
import javax.swing.Action;
50
import com.sun.javadoc.*;
51
import org.netbeans.api.java.source.CompilationController;
51
import org.netbeans.api.java.source.CompilationController;
52
import org.netbeans.api.java.source.ui.ElementJavadoc;
52
import org.netbeans.api.java.source.ui.ElementJavadoc;
53
import org.netbeans.spi.editor.completion.CompletionDocumentation;
53
import org.netbeans.spi.editor.completion.CompletionDocumentation;
Lines 81-88 Link Here
81
        return elementJavadoc.getGotoSourceAction();
81
        return elementJavadoc.getGotoSourceAction();
82
    }
82
    }
83
83
84
    public static final JavaCompletionDoc create(CompilationController controller, Element element) {
84
    public static final JavaCompletionDoc create(CompilationController controller, Element element, Callable<Boolean> callable) {
85
        return new JavaCompletionDoc( ElementJavadoc.create(controller, element) );
85
        return new JavaCompletionDoc( ElementJavadoc.create(controller, element, callable) );
86
    }
86
    }
87
    
87
    
88
}
88
}
(-)a/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java (-1 / +6 lines)
Lines 49-54 Link Here
49
49
50
import java.io.IOException;
50
import java.io.IOException;
51
import java.util.*;
51
import java.util.*;
52
import java.util.concurrent.Callable;
52
import java.util.concurrent.Future;
53
import java.util.concurrent.Future;
53
import java.util.logging.Logger;
54
import java.util.logging.Logger;
54
import java.util.logging.Level;
55
import java.util.logging.Level;
Lines 550-556 Link Here
550
                case ENUM_CONSTANT:
551
                case ENUM_CONSTANT:
551
                case FIELD:
552
                case FIELD:
552
                case METHOD:
553
                case METHOD:
553
                    documentation = JavaCompletionDoc.create(controller, el);
554
                    documentation = JavaCompletionDoc.create(controller, el, new Callable<Boolean>() {
555
                        public Boolean call() {
556
                            return isTaskCancelled();
557
                        }
558
                    });
554
                }
559
                }
555
            }
560
            }
556
        }
561
        }
(-)a/java.source/src/org/netbeans/modules/java/source/JavadocHelper.java (-26 / +68 lines)
Lines 61-66 Link Here
61
import java.util.Set;
61
import java.util.Set;
62
import java.util.StringTokenizer;
62
import java.util.StringTokenizer;
63
import java.util.WeakHashMap;
63
import java.util.WeakHashMap;
64
import java.util.concurrent.Callable;
65
import java.util.concurrent.Future;
66
import java.util.concurrent.TimeUnit;
67
import java.util.concurrent.TimeoutException;
64
import java.util.logging.Level;
68
import java.util.logging.Level;
65
import java.util.logging.Logger;
69
import java.util.logging.Logger;
66
import javax.lang.model.element.Element;
70
import javax.lang.model.element.Element;
Lines 81-86 Link Here
81
import org.openide.filesystems.FileStateInvalidException;
85
import org.openide.filesystems.FileStateInvalidException;
82
import org.openide.filesystems.FileUtil;
86
import org.openide.filesystems.FileUtil;
83
import org.openide.filesystems.URLMapper;
87
import org.openide.filesystems.URLMapper;
88
import org.openide.util.RequestProcessor;
84
89
85
/**
90
/**
86
 * Utilities to assist with retrieval of Javadoc text.
91
 * Utilities to assist with retrieval of Javadoc text.
Lines 88-93 Link Here
88
public class JavadocHelper {
93
public class JavadocHelper {
89
94
90
    private static final Logger LOG = Logger.getLogger(JavadocHelper.class.getName());
95
    private static final Logger LOG = Logger.getLogger(JavadocHelper.class.getName());
96
    private static final RequestProcessor RP = new RequestProcessor(JavadocHelper.class.getName(),1);
91
    
97
    
92
    private JavadocHelper() {}
98
    private JavadocHelper() {}
93
    
99
    
Lines 185-200 Link Here
185
    }
191
    }
186
    
192
    
187
    private static final Map<Element,TextStream> cachedJavadoc = new WeakHashMap<Element,TextStream>();
193
    private static final Map<Element,TextStream> cachedJavadoc = new WeakHashMap<Element,TextStream>();
188
194
    
189
    /**
195
    /**
190
     * Richer version of {@link SourceUtils#getJavadoc}.
196
     * Richer version of {@link SourceUtils#getJavadoc}.
191
     * Finds {@link URL} of a javadoc page for given element when available. This method 
197
     * Finds {@link URL} of a javadoc page for given element when available. This method
192
     * uses {@link JavadocForBinaryQuery} to find the javadoc page for the give element.
198
     * uses {@link JavadocForBinaryQuery} to find the javadoc page for the give element.
193
     * For {@link PackageElement} it returns the package-summary.html for given package.
199
     * For {@link PackageElement} it returns the package-summary.html for given package.
194
     * @param element to find the Javadoc for
200
     * @param element to find the Javadoc for
201
     * @param cancel a Callable to signal cancel request
195
     * @return the javadoc page or null when the javadoc is not available.
202
     * @return the javadoc page or null when the javadoc is not available.
196
     */
203
     */
197
    public static TextStream getJavadoc(Element element) {
204
    public static TextStream getJavadoc(Element element, final Callable<Boolean> cancel) {
198
        synchronized (cachedJavadoc) {
205
        synchronized (cachedJavadoc) {
199
            TextStream result = cachedJavadoc.get(element);
206
            TextStream result = cachedJavadoc.get(element);
200
            if (result != null) {
207
            if (result != null) {
Lines 202-220 Link Here
202
                return result;
209
                return result;
203
            }
210
            }
204
        }
211
        }
205
        TextStream result = doGetJavadoc(element);
212
        TextStream result = doGetJavadoc(element, cancel);
206
        synchronized (cachedJavadoc) {
213
        synchronized (cachedJavadoc) {
207
            cachedJavadoc.put(element, result);
214
            cachedJavadoc.put(element, result);
208
        }
215
        }
209
        return result;
216
        return result;
210
    }
217
    }
211
218
219
    public static TextStream getJavadoc(Element element) {
220
        return getJavadoc(element, null);
221
    }
222
212
    @org.netbeans.api.annotations.common.SuppressWarnings(value="DMI_COLLECTION_OF_URLS"/*,justification="URLs have never host part"*/)
223
    @org.netbeans.api.annotations.common.SuppressWarnings(value="DMI_COLLECTION_OF_URLS"/*,justification="URLs have never host part"*/)
213
    private static TextStream doGetJavadoc(final Element element) {
224
    private static TextStream doGetJavadoc(final Element element, final Callable<Boolean> cancel) {
214
        if (element == null) {
225
        if (element == null) {
215
            throw new IllegalArgumentException("Cannot pass null as an argument of the SourceUtils.getJavadoc"); // NOI18N
226
            throw new IllegalArgumentException("Cannot pass null as an argument of the SourceUtils.getJavadoc"); // NOI18N
216
        }
227
        }
217
218
        ClassSymbol clsSym = null;
228
        ClassSymbol clsSym = null;
219
        String pkgName;
229
        String pkgName;
220
        String pageName;
230
        String pageName;
Lines 258-282 Link Here
258
        if (clsSym.completer != null) {
268
        if (clsSym.completer != null) {
259
            clsSym.complete();
269
            clsSym.complete();
260
        }
270
        }
271
        if (clsSym.classfile != null) {
272
            try {
273
                final URL classFile = clsSym.classfile.toUri().toURL();
274
                final String pkgNameF = pkgName;
275
                final String pageNameF = pageName;
276
                final CharSequence fragment = buildFragment ? getFragment(element) : null;
277
                final Future<TextStream> future = RP.submit(new Callable<TextStream>() {
278
                    @Override
279
                    public TextStream call() throws Exception {
280
                        return findJavadoc(classFile, pkgNameF, pageNameF, fragment);
281
                    }
282
                });
283
                do {
284
                    if (cancel != null && cancel.call()) {
285
                        break;
286
                    }
287
                    try {
288
                        return future.get(100, TimeUnit.MILLISECONDS);
289
                    } catch (TimeoutException timeOut) {
290
                        //Retry
291
                    }
292
                } while (true);
293
            } catch (Exception e) {
294
                LOG.log(Level.INFO, null, e);
295
            }
296
        }
297
        return null;
298
    }
299
300
    private static final String PACKAGE_SUMMARY = "package-summary"; // NOI18N
301
302
    private static TextStream findJavadoc(
303
            final URL classFile,
304
            final String pkgName,
305
            final String pageName,
306
            final CharSequence fragment) {
261
307
262
        URL sourceRoot = null;
308
        URL sourceRoot = null;
263
        Set<URL> binaries = new HashSet<URL>();
309
        Set<URL> binaries = new HashSet<URL>();
264
        try {
310
        try {
265
            if (clsSym.classfile != null) {
311
            FileObject fo = URLMapper.findFileObject(classFile);
266
                FileObject fo = URLMapper.findFileObject(clsSym.classfile.toUri().toURL());
312
            StringTokenizer tk = new StringTokenizer(pkgName, "/"); // NOI18N
267
                StringTokenizer tk = new StringTokenizer(pkgName, "/"); // NOI18N
313
            for (int i = 0; fo != null && i <= tk.countTokens(); i++) {
268
                for (int i = 0; fo != null && i <= tk.countTokens(); i++) {
314
                fo = fo.getParent();
269
                    fo = fo.getParent();
315
            }
270
                }
316
            if (fo != null) {
271
                if (fo != null) {
317
                URL url = fo.getURL();
272
                    URL url = fo.getURL();
318
                sourceRoot = JavaIndex.getSourceRootForClassFolder(url);
273
                    sourceRoot = JavaIndex.getSourceRootForClassFolder(url);
319
                if (sourceRoot == null) {
274
                    if (sourceRoot == null) {
320
                    binaries.add(url);
275
                        binaries.add(url);
321
                } else {
276
                    } else {
322
                    // sourceRoot may be a class root in reality
277
                        // sourceRoot may be a class root in reality
323
                    binaries.add(sourceRoot);
278
                        binaries.add(sourceRoot);
279
                    }
280
                }
324
                }
281
            }
325
            }
282
            if (sourceRoot != null) {
326
            if (sourceRoot != null) {
Lines 303-310 Link Here
303
                        out:
347
                        out:
304
                        for (URL e : roots) {
348
                        for (URL e : roots) {
305
                            FileObject[] res = SourceForBinaryQuery.findSourceRoots(e).getRoots();
349
                            FileObject[] res = SourceForBinaryQuery.findSourceRoots(e).getRoots();
306
                            for (FileObject fo : res) {
350
                            for (FileObject r : res) {
307
                                if (sourceRoots.contains(fo)) {
351
                                if (sourceRoots.contains(r)) {
308
                                    binaries.add(e);
352
                                    binaries.add(e);
309
                                    continue out;
353
                                    continue out;
310
                                }
354
                                }
Lines 313-319 Link Here
313
                    }
357
                    }
314
                }
358
                }
315
            }
359
            }
316
            CharSequence fragment = buildFragment ? getFragment(element) : null;
360
317
            for (URL binary : binaries) {
361
            for (URL binary : binaries) {
318
                JavadocForBinaryQuery.Result javadocResult = JavadocForBinaryQuery.findJavadoc(binary);
362
                JavadocForBinaryQuery.Result javadocResult = JavadocForBinaryQuery.findJavadoc(binary);
319
                URL[] result = javadocResult.getRoots();
363
                URL[] result = javadocResult.getRoots();
Lines 366-373 Link Here
366
        }
410
        }
367
        return null;
411
        return null;
368
    }
412
    }
369
370
    private static final String PACKAGE_SUMMARY = "package-summary"; // NOI18N
371
    
413
    
372
    /**
414
    /**
373
     * {@code ElementJavadoc} currently will check every class in an API set if you keep on using code completion.
415
     * {@code ElementJavadoc} currently will check every class in an API set if you keep on using code completion.
(-)a/java.sourceui/apichanges.xml (+14 lines)
Lines 110-115 Link Here
110
    <changes>
110
    <changes>
111
111
112
112
113
        <change id="ElementJavadoc-create">
114
            <api name="general"/>
115
            <summary>Adding cancelable version of ElementJavadoc.create</summary>
116
            <version major="1" minor="15"/>
117
            <date day="29" month="6" year="2010"/>
118
            <author login="tzezula"/>
119
            <compatibility addition="yes">
120
            </compatibility>
121
            <description>
122
                 Added a cancelable version of ElementJavadoc.create to allow
123
                 code completion to cancel slow call to JavadocForBinaryQuery.
124
            </description>
125
            <issue number="171183"/>
126
        </change>
113
        <change id="ElementOpenForCPInfoAndHandle">
127
        <change id="ElementOpenForCPInfoAndHandle">
114
            <api name="general"/>
128
            <api name="general"/>
115
            <summary>Adding ElementOpen.open(ClasspathInfo info, ElementHandle h)</summary>
129
            <summary>Adding ElementOpen.open(ClasspathInfo info, ElementHandle h)</summary>
(-)a/java.sourceui/nbproject/project.properties (-1 / +1 lines)
Lines 2-5 Link Here
2
javac.compilerargs=-Xlint -Xlint:-serial
2
javac.compilerargs=-Xlint -Xlint:-serial
3
javac.source=1.6
3
javac.source=1.6
4
javadoc.arch=${basedir}/arch.xml
4
javadoc.arch=${basedir}/arch.xml
5
spec.version.base=1.14.0
5
spec.version.base=1.15.0
(-)a/java.sourceui/src/org/netbeans/api/java/source/ui/ElementJavadoc.java (-5 / +20 lines)
Lines 53-58 Link Here
53
import com.sun.source.util.Trees;
53
import com.sun.source.util.Trees;
54
import java.net.MalformedURLException;
54
import java.net.MalformedURLException;
55
import java.util.ArrayList;
55
import java.util.ArrayList;
56
import java.util.concurrent.Callable;
56
import org.netbeans.api.java.source.ClasspathInfo;
57
import org.netbeans.api.java.source.ClasspathInfo;
57
import org.netbeans.api.java.source.CompilationController;
58
import org.netbeans.api.java.source.CompilationController;
58
import org.netbeans.api.java.source.CompilationInfo;
59
import org.netbeans.api.java.source.CompilationInfo;
Lines 121-127 Link Here
121
     * @return ElementJavadoc describing the javadoc
122
     * @return ElementJavadoc describing the javadoc
122
     */
123
     */
123
    public static final ElementJavadoc create(CompilationInfo compilationInfo, Element element) {
124
    public static final ElementJavadoc create(CompilationInfo compilationInfo, Element element) {
124
        return new ElementJavadoc(compilationInfo, element, null);
125
        return create (compilationInfo, element, null);
126
    }
127
128
    /** Creates an object describing the Javadoc of given element. The object
129
     * is capable of getting the text formated into HTML, resolve the links,
130
     * jump to external javadoc.
131
     *
132
     * @param compilationInfo CompilationInfo
133
     * @param element Element the javadoc is required for
134
     * @param cancel a {@link Callable} to signal the cancel request
135
     * @return ElementJavadoc describing the javadoc
136
     * @since 1.15
137
     */
138
    public static final ElementJavadoc create(CompilationInfo compilationInfo, Element element, final Callable<Boolean> cancel) {
139
        return new ElementJavadoc(compilationInfo, element, null, cancel);
125
    }
140
    }
126
    
141
    
127
    /** Gets the javadoc comment formated as HTML.      
142
    /** Gets the javadoc comment formated as HTML.      
Lines 167-173 Link Here
167
                    public void run(CompilationController controller) throws IOException {
182
                    public void run(CompilationController controller) throws IOException {
168
                        controller.toPhase(Phase.ELEMENTS_RESOLVED);
183
                        controller.toPhase(Phase.ELEMENTS_RESOLVED);
169
                        if (linkDoc != null) {
184
                        if (linkDoc != null) {
170
                            ret[0] = new ElementJavadoc(controller, linkDoc.resolve(controller), null);
185
                            ret[0] = new ElementJavadoc(controller, linkDoc.resolve(controller), null, null);
171
                        } else {
186
                        } else {
172
                            int idx = link.indexOf('#'); //NOI18N
187
                            int idx = link.indexOf('#'); //NOI18N
173
                            URI uri = null;
188
                            URI uri = null;
Lines 197-203 Link Here
197
                                            }
212
                                            }
198
                                        }
213
                                        }
199
                                    }
214
                                    }
200
                                    ret[0] = new ElementJavadoc(controller, e, new URL(docURL, link));
215
                                    ret[0] = new ElementJavadoc(controller, e, new URL(docURL, link), null);
201
                                } else {
216
                                } else {
202
                                    //external URL
217
                                    //external URL
203
                                    if( uri.isAbsolute() ) {
218
                                    if( uri.isAbsolute() ) {
Lines 230-236 Link Here
230
        return goToSource;
245
        return goToSource;
231
    }
246
    }
232
    
247
    
233
    private ElementJavadoc(CompilationInfo compilationInfo, Element element, URL url) {
248
    private ElementJavadoc(CompilationInfo compilationInfo, Element element, URL url, final Callable<Boolean> cancel) {
234
        this.trees = compilationInfo.getTrees();
249
        this.trees = compilationInfo.getTrees();
235
        this.eu = compilationInfo.getElementUtilities();
250
        this.eu = compilationInfo.getElementUtilities();
236
        this.cpInfo = compilationInfo.getClasspathInfo();
251
        this.cpInfo = compilationInfo.getClasspathInfo();
Lines 240-246 Link Here
240
        JavadocHelper.TextStream page = null;
255
        JavadocHelper.TextStream page = null;
241
        if (element != null) {
256
        if (element != null) {
242
            // XXX would be better to avoid testing network connections in case we get a source fo anyway
257
            // XXX would be better to avoid testing network connections in case we get a source fo anyway
243
            page = JavadocHelper.getJavadoc(element);
258
            page = JavadocHelper.getJavadoc(element, cancel);
244
            if (page != null) {
259
            if (page != null) {
245
                docURL = page.getLocation();
260
                docURL = page.getLocation();
246
            }
261
            }

Return to bug 188209